I saw a lot of projects where bootstrap is included by a link to a CDN. Does that mean the bootstrap file is downloaded from the internet all the time when the page get reloaded from the server ? Or does the browser cache the side ? What is actually the best practice. To include by CDN or to download the file locally . What would be the advantage of using CDN vs downloaded file ? An obvious disadvantage of CDN is when you lost your internet connection the whole side has no CSS , so in most cases it would not be usable.
Asked
Active
Viewed 1,674 times
-1
-
Does this answer your question? [Why should I use Google's CDN for jQuery?](https://stackoverflow.com/questions/2180391/why-should-i-use-googles-cdn-for-jquery) – BenM Nov 06 '19 at 12:38
-
but what if your internet gets lost . Your application is not usable anymore !! This just happened in my company recently. – Steffi17 Nov 06 '19 at 12:39
-
Yes, that's correct. Using a CDN has its pros and cons, which you must weigh up before making any business decisions about their usage. – BenM Nov 06 '19 at 12:43
-
@Steffi17, the solution is quite straight forward based on your concern. Loading remote script first, if failed, load your local script. There is not magic around it. And depending on the project, if the website or certain page is only used within the company that can be access within local internet anytime, then you might want to always load the local copy. – Yunhai Nov 06 '19 at 23:03
-
is there a command to check if loading of a script failed ? – Steffi17 Nov 07 '19 at 09:57
-
@Steffi17 yes. https://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go . Take this as an idea. You really have to do your own research like `load local script if remote fail` instead of waiting for someone to answer your question. There are tons of SO duplicated questions that cover your problem. – Yunhai Nov 07 '19 at 16:17
1 Answers
1
The main advantage of the CDN is to send a cached copy of the file to the users with all of the static content of your website. Images and stylesheets, though, those are perfect for a CDN.
The disavantadge is that it will be not available if you are working offline.
Also, the CDN is more faster for your request because it's processed by another server.
Hugo Sohm
- 2,224
- 2
- 17
- 33
-
As I said we had a hardware failure and from morning to lunch we had no internet. So without CSS the page was not usable anymore!! For a company I would say it is a dodgy decision to use a CDN for their website. For example radio buttons were no longer in one line but in 4 lines and the header did not fit anymore to the radio buttons because the header was above the radio buttons in just one line – Steffi17 Nov 06 '19 at 12:51
-
If you have some internet issues, you can download your css requirements and it will be good but the CDN is a best way if you want a better UX – Hugo Sohm Nov 06 '19 at 12:53
-
but if the internet is gone , CSS is gone . But I realised chrome had cached a little bit so partially it was usable – Steffi17 Nov 06 '19 at 12:56
-
Yes of course but if you want to download your style files to avoid the internet problems, you can download it and it's a good way. Instead, you will need to update it locally every update – Hugo Sohm Nov 06 '19 at 12:59