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.
4 Answers
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:
2 Comments
good_evening
@DA: Why should I put all javascript in one file if I need that code only in one page? : )
DA.
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 Comment
brunoais
By the time of this that one was already unmaintained. That is abandoned code
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