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

Explain how to use defer to avoid render-blocking when using this library #86

Open
bradmorton1 opened this issue Sep 17, 2019 · 6 comments

Comments

@bradmorton1
Copy link
Contributor

https://www.webpagetest.org/video/compare.php?tests=190916_BZ_60f228bdf766f4f0a23e7be389decabe,190917_71_be05e3ef5dd8be1a16448425cd8b641d

This test proves that loading the cookie consent script interferes with loading the main content of the page. On a 3G quality connection or older, the load time increase is significant

@mikemonteith
Copy link
Contributor

We should add some guidance to our docs about when to use the async attribute etc.

@chrimesdev
Copy link
Member

chrimesdev commented Mar 9, 2020

From Harry Roberts:

According to WPT, cookie-content.js adds 2.9s to our Start Render event. This is a huge amount of time to lose, especially considering in relative terms it represents a 1.8× degradation in performance.

The attached video shows the users’ experience, and this waterfall comparison shows the technical differences.

Can we defer it and stick it near the closing </body>?

@chrimesdev
Copy link
Member

I believe this isn't as simple as just adding the defer tag to the cookie banner JavaScript. When trying it on the NHS website, the cookie banner works OK but the toggle page where you change your answers doesn't work properly. I think some code will need changing in the cookie consent solution.

@mikemonteith
Copy link
Contributor

The NHS.UK toggle code isn't compatible with a defered cookie-consent script, but we could fix that.

@tomdoughty
Copy link
Contributor

The banner can be defered as long as any interaction with the cookie banner's exposed API is wrapped in a load event to prevent a race condition. This is the case everywhere it is used on NHS.UK. We have multiple apps which do defer the banner with no issues.

Further discussion and example implementation is in this merge request

@mikemonteith
Copy link
Contributor

I think this issue is just a matter of explaining this best practice in the docs, as there's no code change needed. I'm going to change the issue title

@mikemonteith mikemonteith changed the title cookie consent js is render blocking Explain how to use defer to avoid render-blocking when using this library Jun 24, 2020
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

No branches or pull requests

4 participants