javascript - Order of script execution when using document.write -


i need run library called fastclick in order handle 300ms click delay that's on mobiles. @ same time, don't need run if i'm not running on mobiles. i'm looking this:

<head>         <script>         var useragent = navigator.useragent;         if (screen.width < 851 || useragent.indexof('ipad') !== -1 || useragent.indexof('iphone') || useragent.indexof('android')) {         document.write('<script src=\"/externalfiles/fastclick.js\"></script>');         }         </script>          //second script         <script>         if (fastclick) {...}         </script> </head> 

as can see, second script checks see if fastclick loaded. on local machine, works. however, i'm wondering if works because file loaded instantaneously file system (ie no delay) or if in fact, document.write statement triggers load , script execution on hold until script loaded. i'm looking latter behavior: scripts loaded via document.write pause javascript parsing until they're loaded?

thanks.

why don't include file , call function when need it? don't have think possibility way involves:

<head>         <script src="/externalfiles/fastclick.js"></script>         <script>         var useragent = navigator.useragent;         if (screen.width < 851 || useragent.indexof('ipad') !== -1 || useragent.indexof('iphone') || useragent.indexof('android')) {                 fastclick(...)         }         </script> </head> 

when non-mobile browser has loaded file 1 time, it's in cache , doesn't slow down page load.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -