Django:Bootstrap CDN或从本地服务器加载Bootstrap文件? [英] Django: Bootstrap CDN or loading Bootstrap files from local server?

查看:81
本文介绍了Django:Bootstrap CDN或从本地服务器加载Bootstrap文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立我的第一个网站.我正在使用Django.我有一个与Bootstrap中的css/js包含有关的问题.

I am trying to make my first website. I am using Django for it. I have a question related to the inclusion of css/js from Bootstrap.

安装和使用BootstrapCDN链接有什么区别?

What is the difference between installing it and linking it using BootstrapCDN?

如果该链接不再可用,会发生什么?会影响网站吗?

What happens if that link is no longer accessible? Will it affect the website?

我不能只将这些文件包含在statics目录中吗?

Can't I just include those files in statics directory?

我的应用程序的base.hml文件中有此文件:

I have this in base.hml file of my app:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="{% static 'flatly.css' %}">
<link rel="stylesheet" href="{% static 'main.css' %}">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

推荐答案

使用CDN加载任何文件(不仅是Bootstrap文件)的要点和原因,而不是将这些文件托管在您的计算机上服务器为 SPEED!

The main point and reason for using CDNs for loading any files (not just Bootstrap files) as opposed to hosting those files on your server is SPEED!

那是因为两件事:

  1. CDN允许并行地即同时加载更多文件!!如果在您自己的服务器上托管相同文件,它们将一个接一个地加载,具体取决于有关您的网页必须加载多少文件(包括图像文件等)的信息,仅此一项就可以对性能产生巨大的影响.

  1. CDNs allow more files to be loaded in parallel i.e. at the same time! While if you host the same files on your own server, they will be loaded one after the other and depending on how many files (including image files etc.) your web page has to load, that alone can make a huge difference in performance.

文件(例如Bootstrap文件)已已缓存在网站访问者的浏览器中!因此,他们根本不必加载它们,这在速度/性能上有更大的提高.这假设您正在使用成千上万个网站使用的CDN来加载相同的文件(因为如果您网站上这些文件的URL/路径与该CDN URL相同,则浏览器将仅使用缓存的文件.用户先前访问过的另一个网站也使用).

Files that are used on MANY websites (such as Bootstrap files for example) are already cached in the browser of your website visitors! So, they don't have to load them at all which is an even greater gain in speed/performance. This assumes that you are using CDNs that are used by thousands or hundreds of thousands of websites to load the same files (because the browser will only use cached files if the URL/path to those files on your website is identical to the CDN URLs that another website, previously visited by the user, also uses).

此外,您可以包括一小段JavaScript或jQuery,以检查外部CDN文件是否可用以及CDN是否由于某种原因而关闭,然后仅此一段JavaScript会从您的本地服务器加载相应的文件.

Also, you can include a small piece of JavaScript or jQuery that checks whether or not the external CDN file is available and if the CDN happens to be down for some reason, then and ONLY THEN that piece of JavaScript would load the corresponding files from your local server.

这篇关于Django:Bootstrap CDN或从本地服务器加载Bootstrap文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆