Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to process images dynamically on request instead of at build-time #223

Closed
zachleat opened this issue Apr 19, 2024 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@zachleat
Copy link
Member

zachleat commented Apr 19, 2024

Making use of the new onRequest Dev Server feature: https://www.11ty.dev/docs/dev-server/#onrequest-for-request-time-processing

This will greatly improve development speed during --serve (for projects that don’t have processed images on disk, already pretty fast using the existing disk cache).

https://www.11ty.dev/docs/plugins/image/#disk-cache

@zachleat zachleat added the enhancement New feature or request label Apr 19, 2024
@zachleat zachleat added this to the Eleventy Image v5.0.0 milestone Apr 19, 2024
@zachleat
Copy link
Member Author

Compatible with Eleventy v3.0.0-alpha.7 or newer.

@zachleat
Copy link
Member Author

This feature will be automatically enabled and require no additional configuration when:

If you aren’t using those methods, you can manually opt-in using the transformOnRequest option and the eleventyImageOnRequestDuringServePlugin plugin:

const Image = require("@11ty/eleventy-img");
const { eleventyImageOnRequestDuringServePlugin } = require("@11ty/eleventy-img");

module.exports = function(eleventyConfig) {
	eleventyConfig.addShortcode("image", async function (src, alt) {
		let metadata = await Image(src, {
			transformOnRequest: process.env.ELEVENTY_RUN_MODE === "serve",
		});

		let imageAttributes = {
			alt,
		};

		// You bet we throw an error on a missing alt (alt="" works okay)
		return Image.generateHTML(metadata, imageAttributes);
	});

	// Serve images on request
	eleventyConfig.addPlugin(eleventyImageOnRequestDuringServePlugin);
};

@zachleat
Copy link
Member Author

Shipping with Image 5.0.0-beta.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant