good_evening
good_evening

Reputation: 21749

How to minify Javascript automatically?

I have many PHP and HTML files. And they have lots of Javascript (jQuery). Is it possible to run some function in PHP or whatever, that that javascript code would be "compressed". Or in other words, minified - automatically? Or it is not possible and I have to do that manually (put all that Javascript code in one file and use compressor online or so on)? Thank you.

Upvotes: 1

Views: 1307

Answers (4)

aWebDeveloper
aWebDeveloper

Reputation: 38352

Do look at https://github.com/web-developer/Resource-Handler. This is a on the fly compressor and minifyer for your js. This requires least configuration or hassle, unlike the other one suggested .

RESOURCE HANDLER

Upvotes: 0

Butifarra
Butifarra

Reputation: 1114

You can use Ant with YUI Compressor, as described in this post.

Upvotes: 1

citizen conn
citizen conn

Reputation: 15390

You can also use JSMin: https://github.com/rgrove/jsmin-php/

Upvotes: 0

DA.
DA.

Reputation: 40673

Unless all of your functions are one-offs, your JS should all be in one file to begin with...or at least all in one file after minimizing.

You can look at PHP-minify as one way to automate things:

http://code.google.com/p/minify/

Upvotes: 2

Related Questions