I'm using an external JS plugin that loads very slowly on mobile devices and want to load it only on desktop.
My JS code is like this
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-53a4066858ab24f0"></script>
I read the answers given here and here but I can't figure out how I can do this for an external JS file. Any ideas how to do this?
I tried this but this removed it from the desktop version as well, despite loading the script (monitored using Network resources in Chrome Dev Tools).
<script>
(function ($) {
if ($(window).width() >= 768) {
url = '//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-53a4066858ab24f0';
$.getScript(url);
}
})(jQuery);
</script>