Closed (works as designed)
Project:
Critical CSS
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
7 Feb 2019 at 03:38 UTC
Updated:
23 Jan 2020 at 22:46 UTC
Jump to comment: Most recent
Related to your code comment:
// TODO Find a better way for setting the onload attribute:
// Due to Drupal escaping quotes inside an attribute,
// we need to set a dummy "data-onload-rel" attribute, only needed
// for the onload attribute.
// 'this.rel="stylesheet"' gets escaped into
// 'this.rel="stylesheet"'.
You might be able to look to the AdvAgg module for ideas on this.
This is an example of the resulting markup from the module:
<link rel='preload' href="path/to/mystylesheet.css" as='style' onload="this.rel='stylesheet'" media="all" />
<noscript><link rel="stylesheet" href="path/to/mystylesheet.css" media="all" /></noscript>
As an aside, Filament Group is now recommending nulling the onload handler with something like this:
<link rel="preload" href="path/to/mystylesheet.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
Comments
Comment #2
albertosilvaSure, I will have a look on it.
Comment #3
albertosilvaComment #4
albertosilvaComment #5
albertosilvaI have added "this.onload=null;" to the
onloadhandler.But I can not get rid of the dummy
"data-onload-rel"attribute because I'm not adding a simple markup (like addAvg is doing) but altering the previously existing array of stylesheets. So, that's an array with all their attributes and I think that breaking it just to avoid that"data-onload-rel"means that no other module could alter that array.So, for the moment, I will keep it as it until there is a way in Drupal to avoid the escaping of quotes.
Comment #6
albertosilvaPostponed until Drupal supports a way to avoid the escaping of quotes inside stylesheet arrays.
Comment #7
albertosilvaClose since there are no plans on Drupal to fix this. Will reopen it when this changes.