Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there libraries for packing and minifying multiple CSS and JS files into one file each?

According to O'Reilly's High Performance Web Sites (pages 15-16), it's highly recommended to make as few HTTP requests as is possible for high-performance. Thus, is there a library for combining multiple JS files into one file, and a library to do this for CSS as well?

For JavaScript, I have at least 4 different libraries being loaded right now, jQuery 1.6.x, a few jQuery plugins, and one application JavaScript file for application logic. I also have 2 CSS files, Bootstrap and my application's CSS file.

Are there tools to facilitate this? It'd be nice to have a tool I could use from Python or from Bash (I'm on Linux) to "compile" and minify the multiple CSS stylesheets.

(If this is possible as a Django addon, even better [ie manage.py packify static/bootstrap.min.css static/application.css ...])

like image 375
Naftuli Kay Avatar asked Oct 11 '11 17:10

Naftuli Kay


People also ask

How do you minify CSS and JS files?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

What bundle would you use to minify CSS and/or JavaScript on a production environment?

Click on wwwroot folder, select the css file you want minified, then right click and choose bundler & minifier. Then from popup minify file. It will be the same file name with the minified version.

Which package helps in Minifying the CSS in Gulp?

gulp-minify-css - npm.


1 Answers

What you are looking for is a css and javascript pipeline. Its becoming a standard for frameworks to provide this kind of tools. For instance, Rails 3.1 has its own asset pipeline built-in.

Not only it will merge your css and javascripts into a single pack, but it will also compress them for even further performance boost.

Fortunately, django also has its own plugin for that

https://github.com/cyberdelia/django-pipeline

like image 138
JavierIEH Avatar answered Nov 08 '22 04:11

JavierIEH