Will all files be compressed by using ob_start(“ob_gzhandler”); at line 1 with PHP?

StackOverflow https://stackoverflow.com/questions/1414527

  •  06-07-2019
  •  | 
  •  

Question

<?php
ob_start("ob_gzhandler");
?>
<script type="text/javascript" src="Util.js"></script>
<script type="text/javascript" src="connection.js"></script>
....
<?php ob_end_flush(); ?>

Will the files included by or also be compressed?

Was it helpful?

Solution

Not in the HTML, no. Those files are request by the browser and the PHP script has no direct relationship with them. You would have to manually rewrite those javascript files to a PHP script that preforms the same action.

OTHER TIPS

When you use an output buffering filter such as ob_gzhandler, it applies only to that specific request. It does not affect other requests a browser may make.

However, from what you have shown, it cannot be determined if Util.js and connection.js will be gzipped or deflated or something else. That's up to the configuration of the server and if files are actually scripts which gzip the content.

(Also, make sure the browser claims to accept gzipped content, and that you tell the browser you are sending gzipped content. You could send gibberish to a browser on accident!)

Short answer: no

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top