简体   繁体   中英

How do I combine javascripts and load them after page load on an asp.net website?

I just read this SE Post where it explains the question asked is similar to what I'm asking. Yslow recommends combining all of your external javascripts, if possible. I've actually taken internal javascripts and made them into an external .js file and put it in my /scripts folder, per some recommendation I found on some website. But this leads me to my 2 (similar) questions; I didn't think separate posts were needed.

(1) - How would I combine javascript codes? Just leave a blank line and then copy and paste the other javascript after the other, and so on, until it's all in one file?

(2) - I have an asp.net website with 5 master pages. 4 of the 5 have 6 javascript files (all minified, some on my own using some compression tool that worked). But I read on a SE post and online that you should load the script(s) after page load . How do you do this on an asp.net website? All my .js files are in the

@bluesmoon gave a nice, thorough answer, but I wasn't able to comprehend it:

To load a script after page load, do something like this:

// This function should be attached to your onload handler
// it assumes a variable named script_url exists.  You could easily
// extend it to use an array of scripts or figure it out some other
// way (see note late)
function lazy_load() {
    setTimeout(function() {
            var s = document.createElement("script");
            s.src=script_url;
            document.body.appendChild(s);
        }, 50);
}

This is called from onload, and sets a timeout for 50ms later at which point it will 
add a new script node to the document's body. The script will start downloading after 
that. Now since javascript is single threaded, the timeout will only fire after onload 
has completed even if onload takes more than 50ms to complete.

I don't really understand what he's saying or how to go about implementing it. So that's all ... I just need help in combining javascripts and loading them (or it) after page load ; I don't see anything saying "onload" in my master pages or .aspx pages. Thank you for any help or guidance anybody can offer me!

看一下Cassette ,然后在关闭身体标签之前渲染包

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM