Quillion Quillion 5, 10 10 gold badges 60 60 silver badges 87 87 bronze badges. Have you attempted to add the code to a js file and link it to your html file? What have you attempted thus far? The script element in question actually has src link. That's why I am confused. How do I include the src element of it in js file? Have you tried adding it as you would a JS library? They have a form to contact them on their website. Add a comment.
Active Oldest Votes. Improve this answer. Programmer Programmer 5, 3 3 gold badges 8 8 silver badges 32 32 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Learn more. Ask Question. Asked 13 years, 3 months ago. Active 1 year, 7 months ago. Viewed k times. Improve this question. Sebastian Simon Add a comment.
Active Oldest Votes. Improve this answer. Walter Rumsby Walter Rumsby 7, 5 5 gold badges 39 39 silver badges 36 36 bronze badges. For example, if you're going to be doing a bunch of jQuery stuff, you would need the library loaded before you actually try to make use of it.
Also, the reason why Yahoo EPT recommends placing JS at the bottom is because the browser must go into single-threaded mode while the JS loads and then executes. If the script is in the head or in the midst of the content, the browser will "pause" while it deals with the JS. By placing the JS at the bottom, the content will be loaded and generally visible so the user can start reading it while the browser is still dealing with the JS.
Modern browsers can also read the "defer" attribute. This is helpful if you're using some sort of framework where you don't have full control of the page. Dig into this article and note that it's a living document so some of the info is outdated: stackoverflow. The best place for it is just before you need it and no sooner. Levi Rosol Levi Rosol 4, 6 6 gold badges 27 27 silver badges 36 36 bronze badges. CSS A little bit off-topic, but Put stylesheets at the top.
Further reading Yahoo have released a really cool guide that lists best practices to speed up a website. You've misunderstood the OP's question. He was asking where in the HTML to put the script tag. He was already using an external file, not inlining the script. Admittedly, this was less clear prior to his edit of the question in April ' Perhaps delete this answer?
Leandro I guess it's because people don't always keep the actual question in mind yet still consider answers such as this one useful. Nonetheless, this answer is useful but not necessarily relevant. It might work better if the vote up tooltip contains more explicit wording, e.
On gzipped Javascript: You can just configure your webserver to compress it as well Matthias Wandel Matthias Wandel 6, 10 10 gold badges 32 32 silver badges 31 31 bronze badges. Sam Hasler Sam Hasler GustyWind GustyWind 2, 3 3 gold badges 40 40 silver badges 49 49 bronze badges.
I you really need to squeeze out every last ms then you probably should do what Yahoo says. Berserk Berserk 2 2 silver badges 3 3 bronze badges. Next Page. Live Demo. Useful Video Courses. JavaScript Online Training 25 Lectures 2.
More Detail. Previous Page Print Page.
0コメント