Home > Database > Mysql Tutorial > body text

使用Python的Django框架中的压缩组件Django Compressor_MySQL

WBOY
Release: 2016-06-01 13:00:10
Original
1715 people have browsed it

为了加快网站的加载速度,我们通常要多js和css进行压缩处理。这些js和css的压缩工作如果都手动处理,费时费力。

Django Compressor 可以实现js/css的自动压缩。Django Compressor在易用性方面做的非常好,按照 文档 做简单的设置后就可以正常工作。强烈建议大家去将文档完整的看一遍(文档很短)。

使用的时候,只需要将css/js放到 compress 标签中 Django Compressor 即可自动进行处理。在debug模式时, Django Compressor 不会对做任何处理。在非debug模式时,Django Compressor会自动对js/css进行压缩,并将压缩后的问题输出到django的 STATIC_ROOT 目录。所以请务必保证 STATIC_ROOT 目录进行了正确的设置。

{% load compress %}
{% compress  [ [block_name]] %}

{% endcompress %}

{% compress css %}

{% endcompress %}
 
Copy after login

coffeescript、less 支持

在开发阶段coffeescript和less可以直接使用js来处理,在正式发布时处于加载速度的考虑需要预先编译成js和css。 Django Compressor 提供 COMPRESS_PRECOMPILERS 设置,根据type类型进行预处理。

COMPRESS_PRECOMPILERS = (
 ('text/coffeescript', 'coffee --compile --stdio'),
 ('text/less', 'lessc {infile} {outfile}'),
 ('text/x-sass', 'sass {infile} {outfile}'),
 ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
 
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!