1

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.

1
  • Look at the plethora of duplicate questions at the bottom-right-hand-corner for hints. Commented Jul 19, 2011 at 1:10

4 Answers 4

2

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/

Sign up to request clarification or add additional context in comments.

2 Comments

@DA: Why should I put all javascript in one file if I need that code only in one page? : )
as I stated, if it's a one-off, then no biggie. If the function is used on more than one page, then putting it in a separate file allows it to be cached.
1

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

Comments

0

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

1 Comment

By the time of this that one was already unmaintained. That is abandoned code
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.