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

kentr created an issue. See original summary.

albertosilva’s picture

Sure, I will have a look on it.

albertosilva’s picture

Status: Active » Needs work
albertosilva’s picture

Assigned: Unassigned » albertosilva
albertosilva’s picture

I have added "this.onload=null;" to the onload handler.

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.

albertosilva’s picture

Status: Needs work » Postponed

Postponed until Drupal supports a way to avoid the escaping of quotes inside stylesheet arrays.

albertosilva’s picture

Status: Postponed » Closed (works as designed)

Close since there are no plans on Drupal to fix this. Will reopen it when this changes.