So this is a simplified question of this ( which im using for reference, to make this question easy...)
Using resize to getScript if above x pixels (jQuery)
If I call for a function that gets a script, to, if that function fires again, it will not load the script again.
Which in ^ that code it is.
getScript - How to only call if not already called
Is an example, but i tried that code awhile ago.
EX:
$(function()
{
var gotscript=false;
$(window).resize(function()
{
//Dekstop
if (window.innerWidth >= 768)
{
if (!gotscript)
{
// GET DESKTOP SCRIPT TO KEEP THINGS QUICK
$.getScript("js/desktop.js", function()
{
gotscript=true;
});
}
}
if (window.innerWidth < 768)
{
if (window.innerWidth >= 768)
{
if (!gotscript)
{
// GET DESKTOP SCRIPT TO KEEP THINGS QUICK
$.getScript("js/desktop.js", function()
{
gotscript=true;
});
}
}
}
}) .resize(); // trigger resize event
})
This loads the script on any window resize event.
I forgot to mention...
var $window = $(window);
function checkWidth() {
var windowsize = $window.width();
////// LETS GET SOME THINGS IF IS DESKTOP
var $desktop_load = 0;
if (windowsize >= 768) {
if (!$desktop_load) {
// GET DESKTOP SCRIPT TO KEEP THINGS QUICK
$.getScript("js/desktop.js", function() {
$desktop_load = 1;
});
}
}
////// LETS GET SOME THINGS IF IS MOBILE
if (windowsize < 768) {
}
}
// Execute on load
checkWidth();
This will work when window size is above 768, and since its only loading this function once, it will not load the script again. What can i do to make the script load if is less then 768, then goes above 768, and not load it again.