Problem/Motivation
Currently, the klaro-no-css.js is defined in the library as following:
js:
/libraries/klaro-js/dist/klaro-no-css.js:
minified: true
preprocess: false
This triggers a warning on Google Pagespeed:
Eliminate render-blocking resources Potential savings of 300 ms
Resources are blocking the first paint of your page. Consider delivering critical JS/CSS inline and deferring all non-critical JS/styles.
…dist/klaro-no-css.js?sofled 69.4 KiB 300 ms
Can we consider adding async or defer to the library?
Steps to reproduce
Tested on Drupal CMS rc1 with Google Pagespeed.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork klaro-3493822
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jan kellermann commentedIn original documentation of klaro-js the loading with "defer" is recommended.
We run in some race-conditions with our own drupal integration and removed the defer-flag.
We will check this again - unfortunately, the impact assessment is not trivial.
Comment #4
jan kellermann commentedCreated MR.
Please review.
Comment #5
jurgenhaasWhen removing
klaroas a function argument in line 1, this causes follow-up issues, e.g. in line 15, line 39 and below, where the klaro object is being referenced. I'm not sure how that can be resolved. Tha browser console prints error messages "klaro is not defined".Comment #6
anybodyFYI: I think
deferwould be the right choice logically and based on our experiences with COOKiES. Still if claro is loaded at the end of the page, the effect should be minimal.See similar comments here: #3493214: COOKiES increases LCP (Google pagespeed)
Comment #7
catchDoes the Klaro Drupal js need to be set to preprocess: false and also set to defer to match? Then the browser should still load the klaro library first, which would mean all the js ought to continue to work then.
Comment #8
jan kellermann commentedYes, I suppose. This is on our list of measures. However, this also delays the rendering of the contextual content dialogs - which probably leads to a worsening of the LCP e.g. for a YouTube video on the start page.
Comment #9
catchI personally would not be too worried about making LCP of a youtube video worse, because it's already bad, and using something like https://www.drupal.org/project/lite_youtube_embed would make it much better, and mean that third party js would only be loaded when it's interacted with, not when the page is loaded.
No idea how that module interacts with Klaro though, if it blocks the lite youtube render too, then that'd be trickier.
Also all the pages without a youtube embed would be faster anyway.
Comment #10
jurgenhaasThis works like a charm. RTBC !!!
Comment #12
jan kellermann commentedThank you for feedback and testing.
I merged the code.
Comment #13
anybodyGreat work @jan kellermann thank you!!
Comment #15
antonio.bertolini commentedHi all,
at line 47 of klaro.drupal.js
I've
Uncaught ReferenceError: klaro is not defined.Any ideas?
Comment #16
antonio.bertolini commentedMy bad.... incomplete library install...
Sorry!!!!!!
The patch works correctly!
Antonio