使用cdn资产(主要是js和css)而不是自己下载资产。
cdn_assets的Python项目详细描述
这个包帮助您使用cdn资产,而不是自己下载js和css。
快速启动
安装此软件包:
pip install cdn_assets
将“CDN资产”添加到已安装的应用程序设置中,如下所示:
INSTALLED_APPS = [ ... 'cdn_assets', ]
我们提供如下过滤器:
{% load cdn_assets %} {% cdn bootcss %} {% asset bootstrap 3.3.5 css bootstrap.min css %} {% asset jquery 2.2.1 jquery.min js %} {% endcdn %} This will output :: <script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script> <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> Explaination :: {% cdn bootcss %} {% asset jquery 2.2.1 jquery.min js %} {% endcdn %} The last parameter for asset filter is js, It would generate <script> If the last parameter is css, then it would be <link rel='stylesheet'> '/'.join() jquery 2.2.1 jquery.min -> jquery/2.2.1/jquery.min adding the js it becomes jquery/2.2.1/jquery.min.js The host is bootcss, so the url would be //cdn.bootcss.com/jquery/2.2.1/jquery.min.js
CDN主机列表:
HOST_MAPPINGS = { 'bootcss': 'cdn.bootcss.com', 'baidu': 'libs.baidu.com', 'sinaapp': 'lib.sinaapp.com', 'aspnetcdn': 'jax.aspnetcdn.com', 'google': 'ajax.googleapis.com', 'upai': 'upcdn.b0.upaiyun.com', 'cdnjs': 'cdnjs.cloudflare.com', 'staticfile': 'cdn.staticfile.org', '360': 'libs.useso.com' }