开发者

Files (jQuery, jQuery UI, prototype) from external server

开发者 https://www.devze.com 2023-03-09 13:48 出处:网络
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?

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"


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.


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消