开发者

compress js files like compass with css (SASS)

开发者 https://www.devze.com 2023-04-01 03:24 出处:网络
Is there something like Compass but for javascript? I\'m interested in a tool where it will take the main js files and all the other files that are included and compress it to a new js file with all t

Is there something like Compass but for javascript? I'm interested in a tool where it will take the main js files and all the other files that are included and compress it to a new js file with all the code on 1 line as soon as you save your changes in 开发者_Go百科whatever file you are working.


Compass includes that functionality. For instance, I use bootstrap.js for one of my projects. I watch the file with Compass and have it minify the file into bootstrap-ck.js, which is the file I refer to in my production code.

I've attached an image which should show you the details. Notice that you can do imports just as you would with Sass or Less.

compress js files like compass with css (SASS)

You'll also be able to have it check the code through JSHint or JSLint. If you're having issues, you can check the Compass documentation or open your config.rb file to see the Compass details for that particular project.

Hope that helps.


You're looking for a Javascript minifier. There are a whole bunch of them to choose from. Try this one or this one, or google for "javascript minifier" for more.

Note that in addition to simply putting all the code on one line, these tools also rename your variables and functions to shorter names, and do a few other tricks to make the code as tiny as possible. The end result should be functionally identical to your original code, but it won't be exactly the same as the code you wrote.


You have a tool from yahoo

http://developer.yahoo.com/yui/compressor/

And you also have a .net tool (if you're working with .net) for this compressor

http://yuicompressor.codeplex.com/


Another recommendation would be UglifyJS

0

精彩评论

暂无评论...
验证码 换一张
取 消