简体   繁体   English

Django-缩小JavaScript文件

[英]Django - minify javascript files

I would like to minify my javascripts. 我想缩小我的JavaScript。 I saw page https://www.djangopackages.com/grids/g/asset-managers/ and checked first few libraries. 我看到了页面https://www.djangopackages.com/grids/g/asset-managers/并检查了前几个库。 It seems to me that those packages are overcomplicated for my case. 在我看来,这些软件包对于我的情况而言过于复杂。 I have not found a tutorial how to achieve simple scenario like 我还没有找到如何实现简单场景的教程

  1. minify my javacript files (probably during collectstatic, or as admin action) 缩小我的Javacript文件(可能是在collectstatic期间,或作为管理员操作)
  2. replace javascripts in my templates with its minified versions 用其最小版本替换模板中的javascript

I will probably have just one file per page, so there is really no reason for compressing. 我可能每页只有一个文件,因此实际上没有理由进行压缩。

Can you give me advice, what library/tutorial I should follow to achieve this behavior? 您能给我建议吗,我应该遵循什么图书馆/教程来实现这种行为?

Django-compressor is the main tool for this, I think. 我认为Django-compressor是实现此目的的主要工具。 As your use case sounds pretty simple, I think it'll be sufficient. 由于您的用例听起来很简单,我认为就足够了。

If your Javascript becomes very complex, it'd be best to work with Javascript asset pipeline tools and try to fit them into Django, this area is not Django's strong point. 如果您的Javascript变得非常复杂,最好使用Javascript资产管道工具并尝试使其适合Django,这不是Django的强项。

Examples (and the rest of the docs) at read the docs . 阅读docs的示例(以及其他文档)。

Try this? 尝试这个?

http://jscompress.com/ http://jscompress.com/

Or this? 或这个?

https://javascript-minifier.com/ https://javascript-minifier.com/

Source: Google search term: minify javascript 资料来源:Google搜索词:缩小javascript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM