I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?
相关问题
- Is there a limit to how many levels you can nest i
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to toggle on Order in ReactJS
- How to get the background from multiple images by
Here's a Python script I made that I use with all my heavy JavaScript projects. I'm using YUICompressor, but you can change the code to use another compressor.
I use it like this (the below is just a code snippet, and assumes that the
compress
function exists in the current namespace):A slightly different take on the solution proposed by Rushabh. Rather than a file based compress function, this is string based and somewhat simpler:
If you're using WSGI middleware you could also use Fanstatic. It's probably some more work to integrate it into your stack than "simply" changing something in Buildout. The things you get with Fanstatic on the other hand are pretty good. It allows you to only send exactly the scripts you need for every page. It also does concatting (bundling) and minification of "resources" (JavaScript and CSS).
I created Minifpy : a tool to merge and minify JS and CSS file by using Python.
This tool use a very easy JSON configuration file to define if files must be merge , minify or not :
Minifpy detect any modifications on JS/CSS files and merge/minify them automatically (useful for development).
The qooxdoo project comes with a Javascript compressor written in Python. Although it's tightly integrated with the framework, you should be able to utilize the compressor component. If you get the latest SDK there is a tool/bin/compile.py command line tool you can use to compress JS files, with various options (use the -h command line switch for help). I'm sure builtout can call this through a shell.
If you want to roll your own you can draw the compressor into your own Python code, by using the Python modules that come with the qooxdoo SDK (under tool/pylib/). It's not documented but you can look at the compile.py script how to achieve that.
Combining Blixt's solution with JS Min. Here is the code:
Just call the
compress(in_files, out_file)
method