What is CDN and how do I enable it in my Javascript files?

Asked

Viewed 3,128 times

10

On a performance verification site I received the message "Use CDN for all Static Assets" for my Javascript files.

What are CDN and how to implement them?

  • 1

    I believe that the best answer to your question is in the very description of this question. http://answall.com/questions/119766/criando-um-cdn-content-delivery-network

5 answers

10


IS Content Delivery Network or content delivery network. In fact it is used more for static content. In general it is a worldwide network of data centers (points of presence) that makes a "kind of cache" (but not exactly) of the content that should be loaded by their sites, giving better performance, not only because they are specialized in it, but also because they are usually closer to who is ordering the content (through geolocation). This way challenges your server to "more noble" activities such as dynamic content generation.

In general it is a very stable and reliable network, besides supporting large volume of access without losing speed, even in cases of attacks. It can be used as a defense. Even if you completely lose access to the site because your main servers are under attack, you may still have a static version of the site being offered. The important thing is that it helps deliver the content. Obviously it is only useful in cases of websites with reasonable traffic or for standard content that is universally used on most websites. But that’s not the focus of this question.

Standard libraries

In some cases it is used by some standard libraries to avoid unnecessary load of something that client already has locally. If you just want this, just use the address that your preferred library uses, as per the question linked above.

jQuery was one of those most used libraries (at the time I responded) and the address where it indicates where to get it from their CDN is https://code.jquery.com/. Clicking on one of them will appear this:

SS jQuery

Then use:

<script
    src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
    integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc="
    crossorigin="anonymous"></script>

Own content

If you want to do for content of your site (image, audiovisual, downloadable files, etc.), you will have to hire the service with some specialized company to have an address where to put this content and reference it on your page.

The exact way you reference on your page depends on each content. But there is no secret, the only difference is that it is not on the same server as the dynamic content, so the address of the file is another location, it will certainly be an absolute URL giving the entire address (the relative address we normally use only works for local content. But it’s standard HTML, nothing special.

Complement

There are those who use CDN for dynamic content, mainly live broadcasts and specialized tasks.

The subject is vast, it has a lot of detail, but I would need more specific questions.

  • 2

    Your answers always great, congratulations master

  • Face your answer was very good.

3

CDN (Content Delivery Network) is an information distribution network that allows providing Web content more quickly to a large number of users, distributing content across multiple servers.

Example of CDN:

Jquery

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

Angular

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular-animate.js"></script>

2

In the context of web development (and concerning the message about static content) Cdns are services where libraries client (in general Javascript and CSS) can be found.

Your focus is on high reliability (uptime, versioning) and performance (transmission rate). For this reason, most CDN services have geographically distributed servers, with the aim of reducing the response time.

1

CDN can be viewed with a service that hosts static files from your website and delivers them to the customer. This causes the load to be reduced.

For this reason on the performance verification site you received the message: "Use CDN for all Static Assets", meaning he’s telling you to use a CDN for the static files.

The full implementation and a good explanation can be seen in this website.

0

Content Delivery Network (CDN or Content Delivery Network), are servers that provide content. Usually, to implement it, is to insert an external source to the project. Example:

Local

<script src="../caminho/script.js"></script>

CDN

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
  • 3

    It would be nice to explain the main function of the CDN.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.