使用cdn资产(主要是js和css)而不是自己下载资产。

cdn_assets的Python项目详细描述


这个包帮助您使用cdn资产,而不是自己下载js和css。

快速启动

  1. 安装此软件包:

    pip install cdn_assets

  2. 将“CDN资产”添加到已安装的应用程序设置中,如下所示:

    INSTALLED_APPS = [
        ...
        'cdn_assets',
    ]
    
  3. 我们提供如下过滤器:

    {% 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
    
  4. 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'
    }
    

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java当使用SAST工具时,为什么我们必须为编译语言(例如C/C++)使用“构建包装器”?   从C++调用java   java在键入时重新存储单词   java Magnolia实例化模块类失败   为什么我可以在java的for循环中创建很少的文件对象   netbeans JAVA:将事件创建为单独的程序。。。可能吗?   标准不使用java关键字的目的是什么?   java如何将列表计数与单个整数值进行比较?   编写谓词练习JAVA技能   Java 8中是否有Scala的等价物?   java有人能指出这段代码的错误吗?这是一个卡片重绘程序,但由于某些原因,一些卡片会重复   java使驱动程序“通用”   java如何在Hibernate中删除多个关联而不实际删除对象