CSS and JS consolidation before compression? Tools? Best practics?

I am working on a one page website that includes about a dozen .js files and possibly half a dozen .css files.

Most .js files are jQuery plugins. In addition to the basic css file, CSS files are intended for the respective jQuery plugins.

YUI Compressor seems to be the favorite for compressing CSS and JS files. However, it only compresses single files.

I would also like to combine the files and (ideally) end up with one .js and one .css file (both are compressed).

Are there any preferred tools that let you automate combining .js and .css files into a single file so that it can then be launched through the YUI compressor?

+3
source share
5 answers

As a result, I found this option:

http://johannburkard.de/blog/programming/javascript/automate-javascript-compression-with-yui-compressor-and-packer.html

This is a batch file that combines local versions of concatenation, YUI Compressor and Dean Edward Packer.

In the end, however, I could not get Packer to work locally. He continued to decompose my .js.

So, I skipped this part, and then executed the compressed YUI code through the online packer and saw only a 1% increase in compression, so I just skipped the Packer step.

In the end, my solution used the above related instructions with a slightly modified batch file:

type .. \ js-in *> jb.js java -jar .. \ yui \ build \ yuicompressor-2.4.2.jar jb.js -o jb-yui.js

() . !

+1

. ( ) .

@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%"

, -.

+2

Source: https://habr.com/ru/post/1717479/


All Articles