I have this jQuery to detect the screen size and then append a file to the header based on the sceen size.
var scriptSrc = '';
var widowWidth = $(window).width();
if(widowWidth >= 1024)
scriptSrc = '/js/desktop.js';
if((widowWidth <= 1023) && (widowWidth >= 768))
scriptSrc = '/js/tablet.js';
else if(widowWidth <= 767)
scriptSrc = '/js/mobile.js';
var script = document.createElement('script');
script.src = scriptSrc;
var head = document.getElementsByTagName('head')[0];
head.appendChild(script);
I have tried to use $(window).resize() with it but I have been unable to remove the file that was originally added before the resize is triggered.
I have a JSFIDDLE for you to change my code on and as you can see it will add the js file based on the screen size but I would like it to change if the screen does too.
Thanks for your time!