3 ms·
Better yet, just allow directory indexes on /js and /css, showing the smaller files that the minified one is built from. You can do this, and also minify them u
by zx2c4 14y ago
Better yet, just allow directory indexes on /js and /css, showing the smaller files that the minified one is built from. You can do this, and also minify them using a Makefile.
zx2c4@albali ~/zx2c4.com $ cat Makefile
JS_DIR = js
CSS_DIR = css
JS_MIN = $(JS_DIR)/scripts.min.js
CSS_MIN = $(CSS_DIR)/styles.min.css
JS_MIN_FILES := $(patsubst %.js, %.min.js, $(filter-out %.min.js, $(wildcard $(JS_DIR)/*.js)))
CSS_MIN_FILES := $(patsubst %.css, %.min.css, $(filter-out %.min.css, $(wildcard $(CSS_DIR)/*.css)))
JS_COMPILER = ~/opt/bin/google-compiler --warning_level QUIET
CSS_COMPILER = ~/opt/bin/yuicompressor --type css
.PHONY: all clean
all: $(JS_MIN) $(CSS_MIN)
%.min.js: %.js
@echo "Compiling javascript" $<
@$(JS_COMPILER) --js $< --js_output_file $@
%.min.css: %.css
@echo "Compiling stylesheet" $<
@$(CSS_COMPILER) -o $@ $<
$(JS_MIN): $(JS_MIN_FILES)
@echo "Assembling compiled javascripts"
@cat $^ > $@
$(CSS_MIN): $(CSS_MIN_FILES)
@echo "Assembling compiled stylesheets"
@cat $^ > $@
clean:
@rm -fv $(JS_MIN) $(JS_MIN_FILES) $(CSS_MIN) $(CSS_MIN_FILES)
You prefix the js/css files with an order number.
js/000-jquery-1.2.3.js
js/001-silly-jquery-plugin.js
js/002-another-silly-jquery-plugin.js
js/010-something-else.js
js/100-fetcher.js
or whatever kind of ordered number scheme you like. This way, the Makefile's auto-discovery of the js/.js and css/.css contents will maintain order.