6

In order to use jQuery, do I have to use the following reference in my html?

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

What if my server does not have an internet connection?

5
  • 1
    what if my server does not have an internet connection? How are you connecting to it if it doesn't have a internet connection? And besides, it's the client which requests that file from the Google CDN, not the server. Commented Feb 23, 2012 at 14:31
  • 3
    @RoryMcCrossan: localhost, I'd imagine. Commented Feb 23, 2012 at 14:32
  • 2
    Rory, not acquainted with a thing we like to call local testing? ;) Commented Feb 23, 2012 at 14:32
  • @minitech damn you with your logic. And you Flater. Commented Feb 23, 2012 at 14:33
  • @mike smith, I've edited second part of your question, because it isn't different question. Ask a new question for it if you want. Commented Feb 23, 2012 at 14:59

5 Answers 5

9

Use this code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="/res/jQuery/jquery-1.7.1.min.js"> \x3C/script>');</script>

This will try to download from the CDN, or otherwise use the local one. You must download the local one first though.

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

Comments

6

It will not work if you don't have internet connection. To work locally you should copy jquery.js to your local directory and give relative path.

 <script src="/jquery/1.5/jquery.min.js"></script>

Comments

3

It is not specifically for this case, but I think you should definitely understand how Client-server works. Also, you should understand what is Client-side scripting.

You would then understand that you (your browser) need to be connected to Internet in order to be able to reach the http://ajax.googleapis.com domain.

If you want to work with it locally, without ever reaching Internet, then download jQuery locally, and refer to it in your script tag.

Comments

2

Download the latest jquery file:

http://code.jquery.com/jquery-1.7.1.min.js

And save it to you project. It will now be available locally so you can reference it like this (only an example):

 <script src="/path-to-your-jquery-file.js"></script>

Comments

1

It does not matter if your server has or has not connection to internet. Only the browser which tries to access page from said server need connection to internet. Server just needs to be "visible" from this browser in question.

It might be better, if you understood the basics of how internet works, before you start playing in developers.

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.