Defer Javascript Parsing
-
How do you defer parsing of javascript with Primer?
I tried several methods:
1. I’ve tried a few plugins
2. I tried adding this toheader.php
://-------defer if (!(is_admin() )) { function defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) ) return $url; // return "$url' defer "; return "$url' defer onload='"; } add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 ); }
3. I tried adding this to functions.php and replacing with the correct URL.
<script type="text/javascript"> function parseJSAtOnload() { var element = document.createElement("script"); element.src = "somejavascriptfiles.js"; document.body.appendChild(element); } if (window.addEventListener) window.addEventListener("load", parseJSAtOnload, false); else if (window.attachEvent) window.attachEvent("onload", parseJSAtOnload); else window.onload = parseJSAtOnload; </script>
I’m using Stout, a Primer child theme. But even with just Primer I get this issue. Though I did not try the plugin method with just Primer. The issue goes away when I change to the Twenty Twenty theme.
Has anyone successfully defered parsing of javascript with Primer?
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Defer Javascript Parsing’ is closed to new replies.