-
Notifications
You must be signed in to change notification settings - Fork 259
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
feat: implement <noscript>
wrapper for lazyloaded images
#240
Conversation
Codecov Report
@@ Coverage Diff @@
## main #240 +/- ##
==========================================
- Coverage 62.25% 61.66% -0.59%
==========================================
Files 23 25 +2
Lines 559 587 +28
Branches 162 169 +7
==========================================
+ Hits 348 362 +14
- Misses 211 222 +11
- Partials 0 3 +3
Continue to review full report at Codecov.
|
The current approach is depending on dom modification in a pre-body script so why we can't take 3rd option? |
@danielroe As a suggestion to phase out complexities towards using native, I would suggest first drop the current polyfill system for |
@pi0 The current approach injects the script immediately before the closing body tag, so the DOM has already been parsed. If not wrapped in I'll think about extracting the polyfill system - challenge will be interacting well with Vue... |
(PR pending for removing polyfill support first then we can properly benchmark for safari polyfill addition cost and method) |
@@ -12,7 +12,7 @@ | |||
"vetur" | |||
], | |||
"scripts": { | |||
"build": "siroc build && mkdist --src src/runtime --dist dist/runtime -d --ext js", | |||
"build": "siroc build && mkdist --src src/runtime --dist dist/runtime -d --ext js && rollup -c", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use unbuild? :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its time has come! 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm thinking using unbuild should be a separate PR though.)
Co-authored-by: pooya parsa <pyapar@gmail.com>
supporting native lazy loading
There are generally speaking two approaches:
<img>
with a data attribute. When the page starts loading (but before hydration),src
can be swapped out with this data attribute if the browser supports lazy loading - but this means that non-JS web scrapers won't see the image, nor will users who have JS turned off in the browser. (Sample library implementing this approach: https://github.com/verlok/vanilla-lazyload).<noscript><img></noscript>
. When the page starts loading (but before hydration), we swap this out on load for<img>
(withsrc
if native lazyloading is supported and an empty gif if not). This ensures that search engines and users without JS can see the image. (Sample library implementing this approach: https://github.com/mfranzke/loading-attribute-polyfill)A third approach:
<img>
with fullsrc
attribute. When the page starts loading (but before hydration), we polyfill lazy loading via an injected script. However, if we load the script post-body, browsers will already have begun requesting the URIs for these images. If pre-body, we can't interact with the DOM to replace or modify these images.Approach
It's complicated to render
<noscript>
with Vue given issues of inherited attributes (for example) so it needs to be injected with a render hook. We also inject a 598 byte minified script into the page body. On page load, but before hydration, this script swaps out the<noscript>
for its<img>
contents (replacing thesrc
with an empty gif if the browser doesn't support lazy loading). If the browser doesn't support lazy loading, then this script adds a 1.13kB lazy loading polyfill.TODO:
@nuxt/image
to be added tomodules
for server-side renderingResources:
closes #50, closes #190, closes #202, closes #213