Microsoft CDN for jQuery or Google CDN? [closed]

2019-01-03 11:59发布

Does it actually matter which CDN you use to link to your jquery file or any javascript file for that matter. Is one potentially faster than the other? What other factors could play a role in which cdn you decide to use? I know that Microsoft, Yahoo, and Google all have CDN's now.

18条回答
爷的心禁止访问
2楼-- · 2019-01-03 12:04

I would advise that you base your usage on the general location of the users you're targeting.

If your site is targeted for general public, then using Google's CDN would be a good choice.

If your site is also targeted at China, then using Microsoft's CDN would be a better choice. I know from my experience, as Google's servers kept getting blocked by the Chinese government, rendering websites that uses them un-loadable.

*Note that you can of cos create region specific sites, e.g. cn.mysite.com to cater specifically for China, but if you're low on resources and time, its worth a consideration.

Full list of Microsoft CDN here. http://www.asp.net/ajaxlibrary/cdn.ashx

They have since renamed to ajax.aspnetcdn.com, which reduces the likelihood of blockage by firewall rules.

查看更多
不美不萌又怎样
3楼-- · 2019-01-03 12:05

My answer is bit different than others, I will go with microsoft if you need jquery validator which almost everyone need if you are using jquery.

Microsoft CDN http connection is Keep-Alive which is big plus when you are requesting multiple items.

So if you need jquery validation then use Microsoft CDN, even if you need jquery ui use microsoft because google not not keeping keep-alive so every request are on it's own. so mixing in that way is plus. if you are using microsoft only for validator then you are doing seperate connection with google server for each request.

查看更多
Anthone
4楼-- · 2019-01-03 12:05

I would use both!

As the Google Jquery hosting has been around a lot longer, the chances are much higher that people will already have it cached compared to the Microsoft one, so I would have it first.

Personally, I would use something like this -

if (typeof jQuery == 'undefined') {  
    // jQuery is not loaded  

  document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></scr" + "ipt>");
        }
} else {
    // jQuery is loaded
}

(Not sure this 100% works, but I was just going to write the idea and not example - This references the Google hosted Jquery and not the Microsoft one as I couldn't find the link)

查看更多
Rolldiameter
5楼-- · 2019-01-03 12:05

It should also be noted that as ajax.microsoft.com is a sub domain of microsoft.com requests send all microsoft.com cookies adding to the overall time it takes to get the file back.

Also, ajax.microsoft.com is using default IIS7 compression which is inferior to the standard compression that other web servers use.

http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js - 33.4K

http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js - 26.5K

Also, as others have mentioned google CDN is way more popular which greatly increases the chance of a file being cached.

So I strongly recommend using google.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-03 12:10

I know I'm chiming in a little late here, but here is the code that I've been using in production. I've never had issues with it, but your mileage may vary. Make sure you test it in your own environment.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>    
<script type="text/javascript">
    !window.jQuery && document.write('<script src="/scripts/jquery-1.4.2.min.js"><\/script>')
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
    !window.jQuery.ui && document.write('<script src="/scripts/jquery-ui-1.8.2.min.js"><\/script>')
</script> 
查看更多
相关推荐>>
7楼-- · 2019-01-03 12:10

I think it depends on where is your targeted audience. You can use alertra.com to check both CDN speed from many locations around the world.

查看更多
登录 后发表回答