1

I have in the past copy and paste a jquery css or js url into my projects.

Recently the question has come up, what if the urls stopped working for some unforeseen reason. Either code.jquery.com is unavailable or what if jquery as a service (or company) closed down.

For instance if i put:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

In my code, and 'code.jquery.com' stops working the site would look different, or become unstable if using a js script.

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

Or I could run a wget and download these files to my servers.

Having:

<link rel="stylesheet" href="css/1.12.1/jquery-ui.css"> 

<script src="js/jquery-1.12.4.js"></script>
1

As with any link on any website: if the link no longer exists, the link will be broken, dead, etc.
But don't worry: if ever the jquery library would go offline, there are many places where you could download a copy from.
Alternatively you could start using a local copy of jquery.

1

Yes and no. When you run anything from your own site, you are in control. The library can also be optimized for delivery, that is, you can modify the code to reduce size or otherwise speed delivery. (I do not recall if that's possible with jQuery.) The disadvantage of that is you have to do it and keep it up to date.

1

There are a few considerations that need to be made before anyone would make this decision. I do both, download to my site or link remotely depending upon what works best.

If you are concerned that these resources will disappear, do not worry. Even if they do disappear, someone would host these resources within seconds and a simple edit could be made to point to the new location. This is the worse case scenario and not likely to happen.

If you link to a remote resource and there is a security problem, that resource could be updated by the developer transparently. I downloaded one JS file that did have a security vulnerability that I had to discover on my own and update. It would have been better in this case had I not downloaded the resource.

In your example, you are using a specific version of a resource. Sometimes this is necessary, however, many sites offer resources without the version number for a reason. For example, version 1.2 may contain important fixes and you are linking to 1.1. If you link by version, you will not see the update. The website would offer a link to the latest version as /latest or something similar. In this way, your code is always up to date.

Sometimes these sites are very busy and may add latency to your website. In this case, there are times where it makes sense to copy the resource to your own site. As well, many times you can optimize these files for better performance over making several connections to uncompressed files.

So the answer to question is really a mixed bag. What is best for you only you can decide. I often link to the resource on the remote site and then test to see if I could improve performance enough to justify downloading. Otherwise, I live it remotely linked. When I do link remotely, I check for dependencies and whether it would be appropriate and possible to link to the resource without a version number. If I can do that, I will.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.