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

Lazy loading images #355

Closed
wants to merge 7 commits into from
Closed

Lazy loading images #355

wants to merge 7 commits into from

Conversation

mikegeyser
Copy link
Contributor

Closes #351.

Changed the generated script, as well as all of the static pages, to use loading='lazy' for all images. I hope I wasn't too heavy handed with the loading="lazy", but it seems reasonable to me and doesn't affect the experience of the site in any way.

@mikegeyser mikegeyser self-assigned this Nov 7, 2019
@mikegeyser mikegeyser added development Building the Almanac tech stack enhancement New feature or request labels Nov 7, 2019
@mikegeyser mikegeyser added this to the SHIP IT! milestone Nov 7, 2019
Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested removing lazy-loading from images that will mostly be above the fold.

src/templates/en/2019/base.html Outdated Show resolved Hide resolved
src/templates/en/2019/chapter.html Outdated Show resolved Hide resolved
src/templates/en/2019/contributors.html Outdated Show resolved Hide resolved
src/templates/en/2019/contributors.html Outdated Show resolved Hide resolved
src/templates/en/2019/contributors.html Outdated Show resolved Hide resolved
src/templates/en/2019/methodology.html Outdated Show resolved Hide resolved
src/templates/en/2019/table_of_contents.html Outdated Show resolved Hide resolved
src/templates/en/2019/table_of_contents.html Outdated Show resolved Hide resolved
src/templates/en/2019/table_of_contents.html Outdated Show resolved Hide resolved
src/templates/en/2019/table_of_contents.html Outdated Show resolved Hide resolved
@ymschaap
Copy link
Contributor

ymschaap commented Nov 7, 2019

Didn't see this ticket, but I also added lazyload on the files in here:

https://github.com/HTTPArchive/almanac.httparchive.org/tree/tables-lazyload-fonts

Let me know what works better (and I will remove).

@ymschaap ymschaap mentioned this pull request Nov 7, 2019
@tunetheweb
Copy link
Member

Didn't see this ticket, but I also added lazyload on the files in here:

https://github.com/HTTPArchive/almanac.httparchive.org/tree/tables-lazyload-fonts

Let me know what works better (and I will remove).

Well as per above conversation, I think your version is overly aggressive and prefer to be selective on which images are lazy-loaded for reasons discussed above.

Does anyone know if it's bad to over use lazy-loading or not? Raised this query to ask Google for clarification: GoogleChrome/web.dev#1850

@AymenLoukil
Copy link
Contributor

s are lazy-loaded for reasons discussed abov

We could use eager for the hero images as described in the documentation of native lazy loading.

@tunetheweb
Copy link
Member

s are lazy-loaded for reasons discussed abov

We could use eager for the hero images as described in the documentation of native lazy loading.

Changed my review above to do that!

@rviscomi
Copy link
Member

rviscomi commented Nov 7, 2019

Getting SyntaxError: Invalid regular expression flags when running this

@mikegeyser
Copy link
Contributor Author

mikegeyser commented Nov 8, 2019

Hi @rviscomi, I'm not sure why that would be, I didn't think we were using anything esoteric. Could it be the /s (dotall) flag that requires a later node version? It seems pretty new.

This functionality seems to be causing quite a few problems, perhaps we shouldn't be doing this right now? We can abandon this PR if you think that would be better.

@tunetheweb
Copy link
Member

Hi @rviscomi, I'm not sure why that would be, I didn't think we were using anything esoteric. Could it be the /s (dotall) flag that requires a later node version? It seems pretty new.

Works for me with node v12.13.0

This functionality seems to be causing quite a few problems, perhaps we shouldn't be doing this right now? We can abandon this PR if you think that would be better.

What's the problem with this functionality (other than this)? You're not getting it confused with the timestamp functionality are you?

@rviscomi
Copy link
Member

rviscomi commented Nov 8, 2019

Hmmm ok. If it works for everyone else it must be me. @mikegeyser could you resolve the merge conflicts and then we can ship this?

@tunetheweb
Copy link
Member

Hmmm ok. If it works for everyone else it must be me. @mikegeyser could you resolve the merge conflicts and then we can ship this?

Isn't it kind of important for you to be able to build chapters? Did you try removing the s from /s to confirm if that was it? And what version of node are you on?

@rviscomi
Copy link
Member

rviscomi commented Nov 8, 2019

Here's the full error:

$ npm run generate
...
almanac.httparchive.org/src/tools/generate/lazy_load_images.js:5
const images_inside_figures = /<figure(?: [^<>]+)?>(?:(?:(?!<figure).)*)(<img)(?:(?:(?!<figure).)*)<\/figure>/gis;
                              ^

SyntaxError: Invalid regular expression flags

I'm using node v8.7.0.


I've updated to v12.13.0 and now the script runs but generates errors having to do with the HTML, for example:

Generating chapter: en, 2019, markup
SyntaxError: Unexpected closing tag "figure". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (249:1)
  247 |     <iframe width="600" height="371" seamless="" frameborder="0" scrolling="no" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vTbHgqcSepZye6DrCTpifFAUYxKT1hEO56585awyMips8oiPMLYu20GETuIE8mALkm814ObJyktEe2P/pubchart?oid=2141583176&amp;format=interactive"></iframe>
  248 |   <figcaption>Figure 3. Element frequencies as of 2019.</figcaption>
> 249 | </figure>
      | ^
  250 | <p>Comparing the latest data in Figure 3 to that of Hixie's report from 2005 in Figure 2, we can see that the average size of DOM trees has gotten bigger.</p>
  251 | <img loading="lazy"
  252 | <figure id="fig5">

Note the weird stray <img loading="lazy" on line 251. I do think something is broken with the script.

@tunetheweb
Copy link
Member

I'm using node v8.7.0.

That explains it! Apparently you have to use the --harmony flag in Node v8 for dotall support. So like this I guess?

npm --harmony run generate

Or upgrade to a decent version of node and stop living in the past 😀

@mikegeyser
Copy link
Contributor Author

Can we perhaps park this change for the moment? I don’t feel entirely comfortable with the PR, it feels like something isn’t quite right.

It’s not actually essential for the release, but could risk destabilization of the generation script over the weekend. I honestly feel like the most responsible thing to do would be to revisit it next week, with fresh eyes, when the rush is off.

@rviscomi
Copy link
Member

rviscomi commented Nov 8, 2019

@mikegeyser +1

@rviscomi rviscomi closed this Nov 8, 2019
@tunetheweb
Copy link
Member

I've updated to v12.13.0 and now the script runs but generates errors having to do with the HTML, for example:

Generating chapter: en, 2019, markup
SyntaxError: Unexpected closing tag "figure". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (249:1)
  247 |     <iframe width="600" height="371" seamless="" frameborder="0" scrolling="no" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vTbHgqcSepZye6DrCTpifFAUYxKT1hEO56585awyMips8oiPMLYu20GETuIE8mALkm814ObJyktEe2P/pubchart?oid=2141583176&amp;format=interactive"></iframe>
  248 |   <figcaption>Figure 3. Element frequencies as of 2019.</figcaption>
> 249 | </figure>
      | ^
  250 | <p>Comparing the latest data in Figure 3 to that of Hixie's report from 2005 in Figure 2, we can see that the average size of DOM trees has gotten bigger.</p>
  251 | <img loading="lazy"
  252 | <figure id="fig5">

Note the weird stray <img loading="lazy" on line 251. I do think something is broken with the script.

I can't repeat this on this branch.

@tunetheweb tunetheweb deleted the lazy-loading-images branch November 17, 2019 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Building the Almanac tech stack enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add native lazy loading for chapter images (inc iframes)
5 participants