Quantcast
Channel: WordPress.org Forums » [W3 Total Cache] Support
Viewing all articles
Browse latest Browse all 19300

andre.nuno on "[Plugin: W3 Total Cache] Defer Javascript after onload event"

$
0
0

Hi,

It's it possible to have a real onload javascript option in the mimify settings?
I tried in generate_script_tag function of /wp-content/plugins/w3-total-cache/lib/W3/Plugin/Minify.php and it works

This way we can move the javascript after the onload event.

The js code for this option will be something like this

<script type="text/javascript">
function w3tc_load_js(scripturl) {
var element = document.createElement('script'); element.src = scripturl; document.body.appendChild(element);
}
function jsonload() { w3tc_load_js('_SCRIPT_URL_'); }
if (window.addEventListener) window.addEventListener('load', jsonload, false);
else if (window.attachEvent) window.attachEvent('onload', jsonload);
else window.onload = jsonload;
</script>

You can test this code in webpagespeed and check that document load is faster with this method.

Best regards,

https://wordpress.org/plugins/w3-total-cache/


Viewing all articles
Browse latest Browse all 19300

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>