String Compression in PHP and JavaScript

Is there a way to compress a long string (like a long JSON string) in PHP and then decompress it in JavaScript?

+4
source share
3 answers

The solution would be to use gzip compression of the entire output of your PHP script - and let the browser handle client-side decompression.

If you are working with Apache, you can use mod_deflate .
Else, in PHP you can use ob_gzhandler - see the example on this manual page.

Then, on the client side (browser), you have nothing to do: decompressions will be processed automatically.


Like sidenote: using mod_deflate , you can configure CSS, Javascript, HTML (well, all data that is text) to be compressed the same way - which will reduce the size of your pages and speed up their loading; therefore, it is worth a little investigation :-)

+3
source
  <?php $str1 = "Test"; $str2 = "Test"; if ($str1 == "Test") echo "OK-1"; if ($str1 == $str2) echo "OK-2"; ?> 
-3
source
 function isSameString( s1, s2 ) { alert( "s1: " + s1.toString() ); alert( "s2: " + s2.toString() ); return s1.toString() == s2.toString(); } 
-3
source

Source: https://habr.com/ru/post/1343880/


All Articles