Add support for Blurhash in FastBoot #172
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Blurhash requires a JS library to decode, no browser understands it natively. This however provides the challenge that SSR (FastBoot) does not show the LQIP until the app is fully hydrated, when the decoding happens as part of the app - as it was implemented before. But for any FastBoot/prember rendered app this is useless, at least for the initial render, as the loading of the actual image has already started - concurrently with also loading the JS - before the placeholder can be shown. When testing this out in a real app (ember-website, see ember-learn/ember-website#769) you could see that a bunch of images have already been fully loaded (thanks to proper sizes and AVIF, yeah!) before the app.js kicked in.
This is now a major refactoring, with a different approach. When Blurhash is used (and only then!), a separate
blurhash.js
script is created (usingbroccoli-rollup
) that is injected into index.html before the actual app's JS. It will decode the blurhashes and apply the decoded image onto all images that have been explicitly tagged (withdata-eri-bh
attribute) in the static HTML rendered by FastBoot. So that happens eagerly before the app is loaded, with just the minimal amount of JS.This script also exposes the blurhash to data-URL function (as a global), so we can reuse this from our SPA for run-time decoding (e.g. new images rendered in a different route after the app has hydrated), without duplicating this in our app's code.
This and the previous effort (see #162) of rendering LQIP through static CSS (generated by the addon) rather than dynamically applying styles (through modifiers) should provide full FastBoot support for our LQIP-techniques. Closes #161.
cc @lolmaus @andreasschacht @lifeart 👆