Open mszylkowski opened 2 years ago
I very strongly support this.
Key points for me:
I think this is definitely worth considering, and am happy about the "better LCP" and "more locales" points. I want to see if we can refine the idea further to address a few points:
The plan is:
Update: This was implemented to completion in amp-story, we have an experiment that we need to roll out for the launch, and then clean up the code
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Summary
21 language bundles are currently bundled in amp-story-1.0.js, and contribute towards 8.7kB of the bundle size (about 16% as of Jan 10, probably around 20% after other performance improvements). Larger payloads contribute towards delays in rendering as other assets (like images) are throttled, as well as the more critical logic in amp-story.js and v0.js that should run ASAP.
We want to load only the document language bundle without having to download the other 20 unused localization bundles. We can serve the localization strings from the AMP CDN as JSON files (where we can automatically compute fallbacks) and fetch the appropriate bundle after amp-story.js is loaded.
Benefits:
Currently the uses of the localization bundles are synchronous to the component build stages, but we would need to asynchronously use these resources so we don't block the rendering until the language bundle is downloaded [draft].
Most of the localized strings are used for:
We can work to load the localization strings as efficiently as possible for each serving type:
FAQ
1) Does this prevent us from having strings displayed from the beginning of the story?
It doesn't, given how fast the translations get downloaded. This is generally faster than the Poppins font lazy-loaded by amp-story-interactive or amp-story-shopping (which has a size of 8kB per font-weight, compared to 0.6kB for the translations). This results in CLS of 0 for all tests I made with decent speeds, and potentially in the order of
10^-4
CLS on other cases, due to how little the UI would shift (which can be reduced to 0 with good styling). This is unless we want to show a huge string in the middle of the screen initially, in which case the delay betweenamp-story.js
and the translations load could increase LCP just a bit, but the CLS would be the same from adding a large text when amp-story loads, or when the translations load. We could get rid of most of this CLS with SSR or good styles (CLS would only happen if adding the text shifts other things, so leaving the space empty would prevent any CLS).2) Do we need to signal screen readers the system layer's aria labels are not loaded (before they load)
Screen readers first read the title of the document when a page is accessed, and this alone would give enough time for the translations to load in +99% of cases before the screen reader even has time to reach any buttons.
3) Can we lazy-load the strings of amp-story-auto-ads as well?
Yes, we can either include it on the main locale bundles or have a separate set of bundles. This is not a priority for now though.
Notifications
/cc @ampproject/wg-approvers @ampproject/wg-stories