问题
If I have to load for example jquery.js file among some (let's tell about 10) other css / js files, what is a better approach?
- load all from the same server that I have my whole app, or
- use some external servers, like https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js etc.
"Using the google.load() method gives your application high speed and global access to a growing list of the most popular, open-source JavaScript libraries"
回答1:
Use Google. There's a good chance this will already be cached on the client's computer since lots of people use it, so it may be faster.
回答2:
Take a look here: Web Performance best Practices
Summarized:
ideally you should have all static content on subdomains like static1.example.org, static2.example.org. Which increases paralellity for downloads (increasing page load/render speed). in addition you should merge css files and js files, minify them and gzip them to reduce the number of roundtrips and the payload size. (mod_pagespeed is a apache module which can do this for you)
Also your content should be cached with a 1-year cache settings and version controlled (by naming convention, also available with mod_pagespeed)
回答3:
External servers, so called CDNs can be used to speed up the website, when e.g. they are located closer, or the file was used on another website and is already cached.
However, if your website is official, must be reliable, SaaS or whatever then using public CDNs is not advised. the option is then to buy commercial CDNs or host internally.
来源:https://stackoverflow.com/questions/6199694/files-jquery-jquery-ui-prototype-from-external-server