Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing web pages with php, javascript, html, and css in them

I have found utilities that can compress html, javascript, and css files individually. However, lets say I have a file called homepage.php with php at the top of the page, css and javascript in the header, html in the body along with more php code and perhaps some more javascript. Sometimes, the chunks with javascript may also have php in it (for transferring php values to javascript). Are there any utilities that can handle compressing such pages?

Going through every file, breaking it apart manually, and compressing everything individually can get very tedious. Even something that can just compress the html and css in the files and ignore the javascript and php would be extremely useful. Most of my javascript is in external js files anyway.

like image 413
user396404 Avatar asked Apr 01 '26 00:04

user396404


2 Answers

If the idea behind this question is to use less bandwidth, then I suggest you use an apache output filter (assuming that you are using apache as webserver anyway). Just filter all PHP scripts and static HTML pages with ie. mod_deflate, and you'll use less bandwidth.

like image 54
wimvds Avatar answered Apr 02 '26 12:04

wimvds


Even if there is not a tool that would let you do all minifaction at once, you could automate this easily with DOM. Just parse the page and find all <script> and <style> elements. Then run their content through third party libs like JsMin or CSSMin and replace the nodes with the output.

However, you could also just enable gzip compression in your webserver, which should be more than enough compression for most websites. Or did you run into any traffic limits lately?

like image 24
Gordon Avatar answered Apr 02 '26 14:04

Gordon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!