# Template compression



## Chris (Jan 15, 2006)

If you're wondering why/what the:

[Output: 99.72 Kb. CMP 90.69 Kb. Net 9.03 Kb. (9.05%)]

Line is at the bottom of every page, I'm testing out some realtime template compression that strips unneeded whitespaces/characters and totally does away with the display of any commented code on your end. 

For example, when I edit templates and styles here, I almost always comment out the sections that I'm working on. So if I'm removing 15 lines of code, I usually leave it in the actual code itself, but comment it out so that your browser doesn't execute it. So if you view the page source, while the HTML isn't getting parsed, the text itself is still being sent to you.

This compression strips the output on the fly, so you get only the code you need sent to your browser and nothing else. The listing at the bottom is the total output, CMP (compression amount) and the percentage the page you're viewing is down from it's original size. 

While 9.05% might not seem like much, a wee quick math:

Average hits per day over the last week: 220880
Avg hits * 9.05k savings: 1998964
Average bandwith savings over 30 days: 1.90636 GB

So in the end, 2GB less traffic coming out = faster pages for all. If you notice any problems, please let me know and I'll see what I can do. The only thing this would "break" per se is text alignment, but since I'm only replacing vBulletin variables, I believe you shouldn't see any odd behavior.

For you web geeks, because I know you're out there, here's how I'm doing it:


```
$page_byte=strlen($output);
$output=preg_replace ('/\r\n(\s*)/', "\r\n", $output);
$output=preg_replace ('/<!-- .*? -->/',"",$output);
```

The second line is the biggest jump so far, just stripping out the comments spikes compression by almost 5%.


----------



## Donnie (Jan 15, 2006)




----------



## Leon (Jan 15, 2006)




----------



## D-EJ915 (Jan 15, 2006)

Cool, and it makes us look like we know something.


----------



## Chris (Jan 16, 2006)

This is out of the "testing" stage and simply enabled. I've stripped the compression stats from the bottom of the page.


----------

