get Script problem

get Script problem

Hi all,

I have a tricky problem here and need your help!

I have done something like this:

       ...
        <link rel="stylesheet" type="text/css" id="css_sheet" href="stylesheet.css" charset="utf-8" />
       ...

$(document).ready( function() {
<!--CSS and JS setting mobile devices-->
mobileDevice();
$(window).on('resize', function() { mobileDevice(); } );
});
function mobileDevice() {
var ww = $(window).width();
if ( ww < 690 ) {
setSize('_mobile');
} else {
setSize('');
}
}
function setSize( size ) {
var $css = $("#css_sheet");
$css.attr("href", "stylesheet"+ size +".css");
}

which works as a switch for CSS stylesheets mobile device/regular monitor.
This works very satisfying and it inspires me to extend this function to also introduce different external script files. So that certain functions in the mobile device variant disappear or change compared to the bigger sized page.

I tried:

        ...
        <script id="index_js" src="libs/index.js"></script>
        ...
   
    <script>
$(document).ready( function() {
<!--CSS and JS setting mobile devices-->
mobileDevice();
$(window).on('resize', function() { mobileDevice(); } );
});
function mobileDevice() {
var ww = $(window).width();
if ( ww < 690 ) {
setSize('_mobile');
} else {
setSize('');
}
}
function setSize( size ) {
var $css = $("#css_sheet");
$css.attr("href", "stylesheet"+ size +".css");
var $js = $("#index_js");
$js.attr("src", "libs/index"+ size +".js");
}
</script>

I know this is very naive ;-)
because perhaps once the scripts are loaded (parsed) they cannot be changed, can they?

Also something like this:


    <script>
$(document).ready( function() {
<!--CSS and JS setting mobile devices-->
mobileDevice();
$(window).on('resize', function() { mobileDevice(); } );
});
function mobileDevice() {
var ww = $(window).width();
if ( ww < 690 ) {
setSize('_mobile');
$.getScript("libs/index_mobile.js");
} else {
setSize('');
$.getScript("libs/index.js");
}
}
function setSize( size ) {
var $css = $("#css_sheet");
$css.attr("href", "stylesheet"+ size +".css");

}
</script>

didn’t work well. Strange things happened in this variant :-) …

Did I explain myself?
Is there any solution to follow my idea in this point?
Or how else would this have to be done?

Thanks for help!

Garavani