A
A
Alexander Arbuzov2014-09-04 09:54:37
JavaScript
Alexander Arbuzov, 2014-09-04 09:54:37

How to "merge" a bunch of js files into one?

Hello. The number of js libraries exceeded the sane number and began to really slow down the loading of the site. I tried to combine it with my hands, but nothing good comes of it - errors come up.
How is it done correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
callback, 2014-09-04
@callback

Google Closure Compiler

Y
yttrium, 2014-09-04
@yttrium

cat 1.js 2.js 3.js > all.js
or in Makefile:

src/all.js: $(wildcard src/*.js)
    cat $^ > [email protected]

you can also clamp it with uglifyjs:
UGLIFY = uglifyjs
...
src/all.js: $(wildcard src/*.js)
    cat $^ | $(UGLIFY) -cmo [email protected]

M
Mikhail Osher, 2014-09-04
@miraage

UglifyJS .
-c = compress, compression
-m = mangle, "mangle" names of variables and functions.
-o = output file name

uglifyjs jquery.js bootstrap.js mylib.js myapp.js -c -m -o compiled.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question