2

I noticed that some programmers use two ways of calling .js file.

1- this way where you must have the js file:

<script src="lib/jquery.js" type="text/javascript"></script>

2- and this way where you don't need the js file :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>

and I want to know which way is better to use.

1
  • I prefer using the first solution because you don't have to have access to the internet when you ( if you ) are working on localhost. Commented Jul 31, 2013 at 5:40

2 Answers 2

1

The first option is using local files, The second option is using a CDN.

A CDN is a group of fast servers with several common use files. Is really useful to save bandwidth and speed up the download of your site.

However, as was mentioned, you would have problems if the end user don't have access to internet.

Basically, if you expect your application to be executed always online, a CDN is a great option. If you are developing an app that could be executed offline (like a CRM for a company) then it would be better to be served using local files.

If the CDN is down, then your website will be broke. But is more likely that your website is down than the CDN.

Sign up to request clarification or add additional context in comments.

Comments

0

Depends.

Method #1 means you have a local copy of the file -- you don't need to rely on an existing path to the internet (from an intranet behind a firewall, spotty internet service, etc). You take care of any caching, and making sure the file exists.

Method #2 may give you a fast planet-wide content-delivery-network (CDN).

I have, and will continue to use both methods... but #2 is easier.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.