Add defer attribute
-
Hi,
i combined all JS files between the HEAD tag into a single one.
1. How can i add a defer attribute to it?
I have the following code in functions.php that add defer=defer to all .js files which are on the footer, but is not adding it to the .js file generated by Autoptimizefunction add_async_forscript($url) { if ( FALSE === strpos( $url, '.js' ) ) { // not our file return $url; } // Must be a ', not "! return "$url' defer='defer"; } add_filter('clean_url', 'add_async_forscript', 11, 1);
2. The JS file generated is placed right after the </title> tag. Is possible to place it right before </head> tag? (i know that is better to load JS after CSS)
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Add defer attribute’ is closed to new replies.