在压缩之前连接 CSS 和 JS?工具?最佳实践?
我正在开发一个单页网站,其中包含大约十几个 .js 文件,也许还有六个 .css 文件。
大多数 .js 文件都是 jQuery 插件。 除了基本 css 文件之外,CSS 文件还用于相应的 jQuery 插件。
YUI Compressor 似乎是压缩 CSS 和 JS 文件的最爱。但是,它仅压缩单个文件。
我还想合并我的文件,(理想情况下)最终得到一个 .js 和一个 .css 文件(都是压缩的)。
是否有任何首选工具可以让您自动将 .js 和 .css 文件合并到一个文件中,以便可以通过 YUI 压缩器运行该文件?
I'm working on a one-page site that is incorporating about a dozen .js files and and maybe a half dozen .css files.
Most of the .js files are jQuery plugins.
Aside from a base css file, the CSS files are for the corresponding jQuery plugins.
YUI Compressor seems to be a favorite for compressing CSS and JS files. However, it only compresses individual files.
I'd also like to combine my files and (ideally) end up with one .js and one .css file (both compressed).
Are there any preferred tools out there that allow you to automate the combining of the .js and .css files into one file so it can then be run through YUI compressor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您了解一点 php,我发现这是最好的方法: http://www.thedanglybits.com/2007/06/21/minify-your-external-javascript-and-css-with-php/
If you know a little, php, I have found this to be the best way: http://www.thedanglybits.com/2007/06/21/minify-your-external-javascript-and-css-with-php/
您可能想查看 sprockets (http://www.getsprockets.com/)。
You might want to check out sprockets (http://www.getsprockets.com/).
我前几天才问过这个问题。在厌倦了网络搜索之后,我想出了这个 hackish(Windows 批处理文件)解决方案。
但如果有一种更自动化的做事方式我真的很喜欢。
I was asking this question only the other day. After tiring of scouring the web, I came up with this hackish (windows batch file) solution.
but I'd really love it if there were a more automated way of doing things.
我最终偶然发现了这个选项:
http://johannburkard.de/blog/programming/javascript/automate-javascript-compression-with-yui-compressor-and-packer.html
它是一个批处理文件,结合了本地版本的串联、YUI 压缩机和迪恩·爱德华的包装机。
但最终,我无法让 Packer 在本地工作。它不断损坏我的 .js。
所以,我跳过了这一部分,然后通过在线 Packer 运行我的 YUI 压缩代码,只看到压缩率进一步增加了 1%,所以就省略了 Packer 阶段。
最后,我的解决方案使用了上面链接的指令,并稍微修改了批处理文件:
键入 ..\js-in* > jb.js
java -jar ..\yui\build\yuicompressor-2.4.2.jar jb.js -o jb-yui.js
也感谢所有其他(有效)解决方案。很多好信息!
I ended up stumbling upon this option:
http://johannburkard.de/blog/programming/javascript/automate-javascript-compression-with-yui-compressor-and-packer.html
It's a batch file that combines local versions of concatenation, YUI Compressor and Dean Edward's Packer.
In the end, though, I couldn't get Packer to work locally. It kept corrupting my .js.
So, I skipped that part and then ran my YUI Compressed code through the online Packer and only saw a 1% further increase in compression, so just omitted the Packer stage.
In the end, my solution used the above linked instructions with slightly modified batch file:
type ..\js-in* > jb.js
java -jar ..\yui\build\yuicompressor-2.4.2.jar jb.js -o jb-yui.js
Thanks for all the other (valid) solutions as well. Lots of good info!
我几乎专门使用这个网站来压缩我的 JS 和 CSS 文件:
http://www.lotterypost.com/js-compress.aspx
http://www.lotterypost.com/css-compress.aspx
I use this site almost exclusively to compress my JS and CSS files:
http://www.lotterypost.com/js-compress.aspx
http://www.lotterypost.com/css-compress.aspx