I have a bit of JavaScript/JQuery code that I have been tweaking in order to have a webpage switch CSS scripts if the page is resized too small, or if it starts up too small.
The resize seems to work great, but I think i may be cheating on the window.onload statement to make the resize check happen. I can see it when I start to load the page and see it have to "think" before switching to the narrow.css.
I am looking for suggestions on how to make this bit of code preform better, or be less taxing on a mobile connection.
"use strict";
var windowsize = $(window).width();
$(window).resize(function() {
windowsize = $(window).width();
if (windowsize < 600) {
document.getElementById("myCSS").setAttribute("href", "css/narrow.css");
} else {
document.getElementById("myCSS").setAttribute("href", "css/mystyles.css");
}
});
//force window size check at load to kick in if statement
window.onload = $(window).resize();