3

In an HTML5 app I'd like to defer the loading of some big JavaScript files to give faster UI control to the user.

Using

<script src="myscript.js" async /> 

Still waits until the script loads before turning things over to the user when I set the throttle to 2G and watch the network traffic in Chrome developer tools.

I've had success executing the following after the page finishes loading:

$.getScript("myscript.js", function () { gApp.wfSuccessDialog.show(); });

(The success dialog is just for seeing that the script finished loading for testing purposes)

This works perfectly well in Chrome, FireFox, and Opera. Heck it even works fine on the Windows 10 Edge browser and Safari on a really old iPhone.

It just will not load the script on IE11. I can step into the minified jQuery code, to see that it runs. It doesn't throw any errors and doesn't download the script.

I've searched high and wide here and elsewhere on the web but haven't found any answers. The closest I found was this post but I am not attaching it to any events -- I'm firing it in my own ajax startup routines and it is definitely running. Just not on IE11.

If anyone has experience with this I'd appreciate the help. Even if it's a different approach all together. I just don't want to have my users wait to download a 400K script library on slower connections before the UI pops. (The script file loads a chart rendering library that can wait while the user configures some options)

Thanks in advance for any assistance!!

P.S. my jQuery comes from: https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js

Community
  • 1
  • 1
hoekma
  • 793
  • 9
  • 19
  • I see that you've tried the "async" attribute, but what about the "defer" attribute? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer – Clayton Leis Jan 12 '17 at 20:27
  • Yes, I tried that too. It still blocked the UI until the script fully downloaded. – hoekma Jan 13 '17 at 02:24
  • I'm having the exact same issue. Did you ever solve this? – Jay May 25 '17 at 21:43
  • Jay -- no I didn't. I had to switch to "get it done" mode (that app that is, not this attempt at performance gain) and had to keep the loading as a blocking vs. non-blocking method. Sorry, I couldn't help more, but do let us know if you figure it out. – hoekma May 25 '17 at 23:14

0 Answers0