简体   繁体   中英

Javascript: http source vs server

I use JS here and there mainly for slideshows, form validation, drop down sitenav (next step) but I have a few noobie questions if some one has the time...

I have been able so far just to use a jquery library on my server but recently start using a calendar for clients to select a date of birth. The calendar required these sources.

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

My instinct tells me I should have these.js and.css files on my server, is it bad practice to use http sources? I'm currently keeping the links because I need to reference these libraries from different directories of my site.

Are these jquery plugins or is it Ajax? as they're not in the main jquery library. I thought Ajax was an MS alternative to JQuery but now I'm confused... Is there a common large library people like to use or is it common to just add smaller ones here and there?

Any help much appreciated.

What you're doing is actually the preferred option. Serving content via a CDN will (generally) make page loads faster for your users. Just make sure you have some kind of backup code in case the CDN goes down.

As to the second part of your question. Javascript is a language. jQuery is a framework built on top of Javascript and Ajax is a technique that is used in Javascript to make page more interactive. They are related, but are not alternatives to each other.

Further reading

jQuery via Google CDN best practices

jquery from cdn

Microsoft CDN for jQuery or Google CDN?

Actually using the google code repository like this has some advantages over storing these files on your own server. For one thing, it might speed up the client because some folks will not have to download the js files since their browser would have cached these files on previous use.

jQuery is a library of functions for making cross browser javascript including AJAX easier. AJAX is a technique for asynchronously requesting server side resources. It is not equivalent to jQuery.

You have included the core jquery library and the jquery UI library in the code snipet that you provided. This is common. In addition there are hundreds of plugins that you optionally can include as needed.

You are really confused re: AJAX vs jQuery. AJAX is short for Asynchronous JavaScript And XML (although today the XML portion is usually replaced with JSON). In essence, it allows JavaScript to send requests to the server and handle the response to those requests without requiring a new page load. This is facilitated by the XMLHttpRequest JavaScript object which does most of the heavy lifting. AJAX was originally developed/discovered by Microsoft. For more info, see: http://en.wikipedia.org/wiki/Ajax_%28programming%29

jQuery is a different beast altogether. It's a JavaScript framework which focuses on streamlined DOM manipulation through use of its CSS selector engine, simplifying AJAX itself, and otherwise equalizing things across browsers. It's not an alternative for AJAX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM