Pergunta

Estou trabalhando em um site de uma página que está incorporando cerca de uma dúzia de arquivos .js e talvez meia dúzia de arquivos .css.

A maioria dos arquivos .js são plugins jQuery. Além de um arquivo CSS base, os arquivos CSS são para os plugins jQuery correspondentes.

Compressor yui Parece ser o favorito para comprimir arquivos CSS e JS. No entanto, ele apenas comprime arquivos individuais.

Eu também gostaria de combinar meus arquivos e (idealmente) acabar com um arquivo .js e um .css (ambos compactados).

Existem ferramentas preferidas por aí que permitem automatizar a combinação dos arquivos .js e .css em um arquivo para que ele possa ser executado através do compressor YUI?

Foi útil?

Solução 4

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!

Outras dicas

Se você conhece um pouco, PHP, achei que essa é a melhor maneira: http://www.thedanglybits.com/2007/06/21/minify-your-external-javascript-and-css-with-php/

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

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.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top