惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
G
Google Developers Blog
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
J
Java Code Geeks
U
Unit 42
云风的 BLOG
云风的 BLOG
阮一峰的网络日志
阮一峰的网络日志
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Docker
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
V
V2EX
T
Tailwind CSS Blog

The Eleventy Firehose

New Sponsorship Tiers for the Build Awesome Kickstarter Securely Publishing our Packages to npm Back Build Awesome Pro and make it easier to build for the web! The Possum Mascot, now with additional Awesome Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Release Import v1.0.20 · 11ty/import Release Import v1.0.21 · 11ty/import Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Cozy Keyboard Build and Build Awesome AMA Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) A few demos of Editing and Collaboration in Build Awesome Pro (as always, AMA!) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Bluesky: May 6, 2026 at 7:54:00 PM UTC An Awesome Theming Demo with Dave Gandy (and more Build Awesome AMA) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Release v8.0.0 · 11ty/eleventy-plugin-vite Build Awesome Pro Kickstarter AMA
Quick Tip: Inline Minified JavaScript
Zach Leather · 2026-06-07 · via The Eleventy Firehose

Originally posted on The Simplest Web Site That Could Possible Work Well on zachleat.com

This tip works great if you have small JS utilities that you’d like to have in your <head>. For example, this works great with the Filament Group loadJS or loadCSS utilities.

Installation

npm install terser to make the terser minifier available in your project.

Configuration

Add the following jsmin filter to your Eleventy Config file:

eleventy.config.js

import { minify } from "terser";

export default function (eleventyConfig) {
	eleventyConfig.addFilter("jsmin", async function (code) {
		try {
			const minified = await minify(code);
			return minified.code;
		} catch (err) {
			console.error("Terser error: ", err);
			// Fail gracefully.
			return code;
		}
	});
};
const { minify } = require("terser");

module.exports = function (eleventyConfig) {
	eleventyConfig.addFilter("jsmin", async function (code) {
		try {
			const minified = await minify(code);
			return minified.code;
		} catch (err) {
			console.error("Terser error: ", err);
			// Fail gracefully.
			return code;
		}
	});
};

Create your JavaScript File

Add a sample JavaScript file to your _includes directory. Let’s call it sample.js.

// Hi
console.log("Hi");

Capture and Minify

Capture the JavaScript into a variable and run it through the filter (this sample is using Nunjucks syntax)

<!-- capture the JS content as a Nunjucks variable -->
{% set js %} {% include "sample.js" %} {% endset %}
<!-- feed it through our jsmin filter to minify -->
<script>
{{ js | jsmin | safe }}
</script>

Warning about Content Security Policy

WARNING

If you are using a Content Security Policy on your website, make sure the script-src directive allows 'unsafe-inline'. Otherwise, your inline Javascript will not load.