在压缩之前连接 CSS 和 JS?工具?最佳实践?

发布于 2024-08-04 23:38:03 字数 386 浏览 8 评论 0原文

我正在开发一个单页网站,其中包含大约十几个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甚是思念 2024-08-11 23:38:03

如果您了解一点 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/

最笨的告白 2024-08-11 23:38:03

您可能想查看 sprockets (http://www.getsprockets.com/)。

You might want to check out sprockets (http://www.getsprockets.com/).

半夏半凉 2024-08-11 23:38:03

我前几天才问过这个问题。在厌倦了网络搜索之后,我想出了这个 hackish(Windows 批处理文件)解决方案。

@echo off
set TUNA_ROOT=C:\path\to\webroot
set YUI_COMPRESSOR_PATH=C:\path\to\yuicompressor-2.4.2\build
set TEMP_JS_FILE=%TUNA_ROOT%\scripts\all_scripts_temp.js
set OUTPUT_JS_FILE=%TUNA_ROOT%\scripts\tuna_min.js
if exist "%TEMP_JS_FILE%" del "%TEMP_JS_FILE%"
if exist "%OUTPUT_JS_FILE%" del "%OUTPUT_JS_FILE%"
type "%TUNA_ROOT%\Scripts\MicrosoftAjax.js" >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
type "%TUNA_ROOT%\Scripts\MicrosoftMvcAjax.js" >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
rem ...and so on...
java -jar "%YUI_COMPRESSOR_PATH%\yuicompressor-2.4.2.jar" -v --charset utf-8 -o "%OUTPUT_JS_FILE%" "%TEMP_JS_FILE%"
if exist "%TEMP_JS_FILE%" del "%TEMP_JS_FILE%"

但如果有一种更自动化的做事方式我真的很喜欢。

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.

@echo off
set TUNA_ROOT=C:\path\to\webroot
set YUI_COMPRESSOR_PATH=C:\path\to\yuicompressor-2.4.2\build
set TEMP_JS_FILE=%TUNA_ROOT%\scripts\all_scripts_temp.js
set OUTPUT_JS_FILE=%TUNA_ROOT%\scripts\tuna_min.js
if exist "%TEMP_JS_FILE%" del "%TEMP_JS_FILE%"
if exist "%OUTPUT_JS_FILE%" del "%OUTPUT_JS_FILE%"
type "%TUNA_ROOT%\Scripts\MicrosoftAjax.js" >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
type "%TUNA_ROOT%\Scripts\MicrosoftMvcAjax.js" >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
echo. >> "%TEMP_JS_FILE%"
rem ...and so on...
java -jar "%YUI_COMPRESSOR_PATH%\yuicompressor-2.4.2.jar" -v --charset utf-8 -o "%OUTPUT_JS_FILE%" "%TEMP_JS_FILE%"
if exist "%TEMP_JS_FILE%" del "%TEMP_JS_FILE%"

but I'd really love it if there were a more automated way of doing things.

可爱暴击 2024-08-11 23:38:03

我最终偶然发现了这个选项:

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!

音栖息无 2024-08-11 23:38:03

我几乎专门使用这个网站来压缩我的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文