Click to See Complete Forum and Search --> : How to compress HTML?


ssureshkumar
06-28-2006, 11:31 AM
hi all,

Is there any way to compress a html string in javascript?

(Ex)

var html = document.getElementById('sampleDiv').innerHTML;

This html is a very large string.

when I save this html as a HTML file, the size of the file is 1.3MB.

Now, If I send this html string through Post, it takes longer time to save.

So only, I am asking "Is there any way to compress this html using javascript?".

Please help. Its urgent.

Thanks in advance for any help.

Regards,
Suresh.

phpnovice
06-28-2006, 12:11 PM
Not "compress" per se. You can certainly remove "extra" white space (see below). But you cannot automatically restore that white space at the other end. That is why I say this is not actually a "compression" operation.

var html = document.getElementById('sampleDiv').innerHTML;
html = html.replace(/\s+/g, " ");