drupal-7drupal-hooks

How to add an "onload" attribute to css links as like as generated by advagg in Drupal 7


I want to add attribute rel ='preload' and onload="this.rel='stylesheet'" as done in advagg ?I have done in hook_css_later function but no luck . Here is my code

function page_speed_css_alter(&$css) {


        foreach ($css as $key=>&$item) {
            if (file_exists($item['data'])) {
                $item['preprocess'] = FALSE;
                $item['attributes']['rel'] = "preload";
                $item['attributes']['onload'] = "this.rel='stylesheet'";
            }
        }
}

Solution

  • You’ll have to patch core if you don’t want to use advagg. Any reason why you don’t want to use it?