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

Fix Lighthouse Audit warning: missing noscript block #954

Closed
wants to merge 1 commit into from
Closed

Fix Lighthouse Audit warning: missing noscript block #954

wants to merge 1 commit into from

Conversation

rosenbjerg
Copy link

@rosenbjerg rosenbjerg commented Jan 25, 2020

Adds a noscript block to the body of the template, to inform visitors that javascript is required.
Fixes the warning in Lighthouse Audit:
https://web.dev/without-javascript/?utm_source=lighthouse&utm_medium=devtools
Placed in body to support html4 as well as html5

Adds a noscript block to the head of the template, to inform visitors that javascript is required.
Fixes the warning in Lighthouse Audit:
https://web.dev/without-javascript/?utm_source=lighthouse&utm_medium=devtools
Placed in body to support html4 as well as html5
@rosenbjerg rosenbjerg requested a review from developit January 26, 2020 00:41
Copy link
Member

@prateekbh prateekbh left a comment

Choose a reason for hiding this comment

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

Preact CLI prerender it's pages, therefore this warning should not be present in the out of the box setup. Are you using --no-prerender flag?

@rosenbjerg
Copy link
Author

No, I am not using --no-prerender flag, and I can also see in the index.html that it contains prerendered components.
Still, I get the above mentioned warning when running a Lighthouse Audit.
I know it is not a real problem, but it is so easy to fix for all users of preact-cli.

If the prerendering process empties the body as part of the rendering, it might be necessary to move the noscript tag to the head of the template document. But then it will "only" benefit HTML5 browsers

@developit
Copy link
Member

developit commented Jan 26, 2020

Body content from the template is preserved during prerendering.

I'm on the fence about this one. It seems like lighthouse is recommending an actively harmful technique here, though checking the audit description I'm not sure it is?

Lighthouse disables JavaScript on the page and then inspects the page's HTML. If the HTML is empty, the audit fails.

One potentially interesting thing to note here is that Preact CLI can be used to produce apps that are entirely reliant on JS, or apps that don't need it at all to function. I think one of the key indicators of this would be whether or not --prerender-urls is passed to preact build. Without that argument it's difficult to build something that works with JS disabled, and the noscript tag is probably warranted.

Just so I'm following along, how were you getting lighthouse to produce this warning? A freshly installed Preact CLI app?

@rosenbjerg
Copy link
Author

rosenbjerg commented Jan 26, 2020

No, good thing to point out. It is not a freshly installed Preact CLI app, but a Preact CLI app I've been working on for some time.
I find it strange that the check fails, as when I visit the page with Javascript blocked I see the prerendered elements, so body is definitely not empty.
But I completely agree that having a noscript block in the body of webapps, that have a functional prerendered front page, is both unnecessary and would look bad.

@developit
Copy link
Member

Just a thought - any chance you noticed this audit failing during development mode? (npm start / preact watch)

During development mode prerendering is disabled, since it breaks caching.

@rosenbjerg
Copy link
Author

No, it was built with yarn build / preact build.
It was build using Preact 8.2.1 and some not-latest version of preact-cli.
I have since upgraded the project to Preact X and the newest version of preact-cli, but I've not yet deployed that. Hopefully tomorrow though. I can report back after testing if the warning is gone?

@rosenbjerg
Copy link
Author

rosenbjerg commented Jan 29, 2020

Just deployed and tested using Preact X.
Best practice score went from 93 to 100, which is nice 👍
But I still receive that warning. I have again confirmed that it is prerendered, and that the body contains this prerendered html.
If I disable javascript and refresh, I can see these elements.
So the page is most definitely not empty. I'm not sure what triggers this warning, but it seems like a false positive in this case.

@ForsakenHarmony
Copy link
Member

@prateekbh I'd assume most users of preact-cli don't make completely static sites with it, so not having javascript would probably break stuff

Should probably be configurable or smth

@rosenbjerg rosenbjerg closed this by deleting the head repository Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants