What is the simplest javascript function to request a .js file?

I'm just wondering what the simplest javascript function will request a server side .js file. I currently have a jquery-1.4.2.min file that weighs 70 kB, and I decided that there should be a way using javascript to request this file. Thus, if the user does not have javascript enabled, the function will be ignored and the jquery file will not need to be loaded, thereby speeding up page loading and reducing the bandwidth used by the server.

Also, if this works, will the file be downloaded, or will it begin to be used? Thanks in advance!

+4
source share
3 answers

Most browsers no longer load JavaScript when it is disabled, so this is a great optimization for most browser users. If I can find the question on it, I will update this ... but this is something you do not need to handle :)

Edit: Here is this question , although I think there is another similar one.

Something else to keep in mind, as the user will only download it once if your cache headers are set correctly . Also look using the CDN for your jQuery .

+4
source

If the user does not support javascript, <script> elements with src attributes will be ignored.

0
source

If you really want this, you can document.write () the script tag or create a script element and add it. If js is disabled, this will never happen. But others have already mentioned that for most modern browsers, the script tag is simply ignored if js is disabled, so it overflows.

0
source

All Articles