caching - Is it possible to preload a JavaScript file one page earlier than it will be used? -
because of system of dependencies less formalized i'd like, have very, large "master" js file contains pretty large kitchen sink use in every page in app; is, once you've logged in.
it takes few seconds load, few seconds aren't great first-time experience @ logged-in homepage. so, i'd find way of loading script on login page, when browser requests on homepage, either gets 304 not modified response, or knows not re-request it. here's i've tried.
just including <script>
this unfortunately doesn't work because script in question doesn't have "definition guards" in place. including on page messes login page because of <div>s expects have present. it's built through dojo, , don't want hack built file, don't want surround code in such check.
grab xhr
i had fix in place while, , appears work okay in chrome; once login page loaded, script sends out xhr "js/masterfile.js" , nothing it. assumption long cache headers okay, browser hold onto when later needs file script. said, turns out browsers don't seem work way. reuse "text" got xhr, others seem cache scripts differently other content; it's possible that's security-related issue them.
load in iframe
this kind of entering rocky territory, don't iframes, , it's request. but, doing @ least let browser cache script in right way. introduces lot of code complication though, , i'm hesitant settle on this.
if helps @ all, scripts amd-compatible; but, master script in question "boot layer" contains basic definitions of require/define.
well, found possible way of doing this; don't have time thoroughly test it, appears work on basic level.
<script src="mymasterscript.js" type="text/definitelynotjavascriptnopenosir"></script> this works in interesting way. can see request made script source, , if it's valid javascript, execute. (as found referring jquery cdn) however, browser's console squelch kind of errors occur running it; ie, "oh. maybe wasn't supposed run that".
for own purposes, still need figure out, based on jquery scenario, whether might still mess page degree.
Comments
Post a Comment