vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Graveyard (https://vborg.vbsupport.ru/forumdisplay.php?f=224)
-   -   Board Optimization - Page Output Compression - Whitespace stripper. (https://vborg.vbsupport.ru/showthread.php?t=69787)

buro9 09-22-2004 10:00 PM

Page Output Compression - Whitespace stripper.
 
No longer supported by the author.

nexialys 09-23-2004 04:11 PM

this have been done in another hack related to templates compression...

most of the time, it's not good to have such a feature because html is not written well, or is not xhtml relevent...

buro9 09-23-2004 04:18 PM

Quote:

Originally Posted by nexialys
this have been done in another hack related to templates compression...

I did search, maybe you could point to where this is.

Quote:

Originally Posted by nexialys
most of the time, it's not good to have such a feature because html is not written well, or is not xhtml relevent...

The hack doesn't break things, it doesn't affect JavaScript, etc... it merely collapses white space.

As both HTML and XHTML renderers ignore white space the hack can't possibly do anything that the HTML or XHTML wasn't already doing.

I've tested it on my forum and been sure to not upset anything anywhere... I only replace multiple white spaces with a single space... there is no chance a renderering engine will alter what it does because of this.

If I didn't put back 1 white space for the many taken out, then I would agree that I might be affecting the page display or something... as someone might've relied on spacing. However, I leave a single space in there for that reason.

Please show me how my hack does what you imply.

Red Blaze 09-23-2004 08:14 PM

I'm using 3.0.0, and I had to do something else, and still worked.

You see, I didn't find:

PHP Code:

if (DB_QUERIES
  { 

But I did find:

PHP Code:

    $pageendtime microtime(); 

I just put:

PHP Code:

$patterns = array('/\>\s+\</''/^\s*/m'); 
    
$replace = array('> <'''); 
    
$vartext preg_replace($patterns$replace$vartext); 

AFTER what I had to find and it works just as you said. Now my forums are running faster. ^^;;

buro9 09-23-2004 08:48 PM

Quote:

Originally Posted by Sonikku
I'm using 3.0.0, and I had to do something else, and still worked.

You see, I didn't find:

PHP Code:

if (DB_QUERIES
  { 

But I did find:

PHP Code:

    $pageendtime microtime(); 


Strange indeed.

I've just checked the default file from Jelsoft for vBulletin 3.0.3 and the code as I've pasted it is on line 1852. So it is there when shipped.

You must've removed it at some point, maybe for another hack?

Well... no worries. If it didn't have the if (DB_QUERIES) block then you would be best to place the hack code BEFORE the $pageendtime variable. Otherwise the stat you get telling you how long the page took to load will not reflect the inclusion of the hack, as the $pageendtime is literally the timestamp of the page as it finishes being generated.

buro9 09-23-2004 08:49 PM

Hehe... I just noticed you said 3.0.0. Well, the hack version does say 3.0.3 ;)

It works anyway... just place the hack BEFORE the $pageendtime variable is set :)

58sniper 09-23-2004 09:13 PM

That won't work if someone uses the <pre> tag, which utilizes whitespace for formatting.

buro9 09-23-2004 10:24 PM

Quote:

Originally Posted by 58sniper
That won't work if someone uses the <pre> tag, which utilizes whitespace for formatting.

A fine point... added a 'lite' version to the first post that leaves white space at the beginning of lines alone.

However if you have a tech site in which you paste lots of HTML, etc... and you want to preserve space within that. Then you'd be best not using this hack at all ;)

Ghostsuit 09-24-2004 01:40 AM

Simple and effective. Oh and anyone that has VB3 MicroStats hack installed will not be able to find

Code:

if (DB_QUERIES)
  {
    $pageendtime = microtime();

so place it before

Code:

if (DB_QUERIES)
                {
                        $ms = '';

Thats should do the job.

mrboz 09-25-2004 10:17 PM

wow - this makes every page load much faster

thanks very much, great hack.

buro9 09-25-2004 11:47 PM

Quote:

Originally Posted by mrboz
wow - this makes every page load much faster

thanks very much, great hack.

Your site will be even quicker if you let vBulletin store your CSS as external files. Then they can cache in the browser and you send less with each page request :)

turbidblue 09-26-2004 12:09 AM

Quote:

Originally Posted by buro9
Your site will be even quicker if you let vBulletin store your CSS as external files. Then they can cache in the browser and you send less with each page request :)


how?

[high]* turbidblue is interested ;)[/high]

buro9 09-26-2004 12:31 PM

Quote:

Originally Posted by turbidblue
how?

[high]* turbidblue is interested ;)[/high]

Check your AdminCP options:

AdminCP > vBulletin Options > Style & Language Settings > Store CSS Stylesheets as Files? = Yes

Note that vBulletin needs to be able to write the files to the folder:
Quote:

If you would like to store the CSS stylesheet for each style as a file, you must ensure that you have a directory called 'vbulletin_css' inside the 'clientscript' folder, and that the web server has permission to write and delete files within that directory.
So you will need to create the directory is it doesn't exist, and then CHMOD the directory in question to have permissions something like 755 or 775 depending on how your Apache is configured. You don't want to CHMOD it 777... you never want to do that.

You can usually set permissions via FTP programs or SFTP... but it can always be done from SSH or Telnet :)

buro9 09-26-2004 12:35 PM

Quote:

Originally Posted by buro9
Check your AdminCP options:

AdminCP > vBulletin Options > Style & Language Settings > Store CSS Stylesheets as Files? = Yes

Note that vBulletin needs to be able to write the files to the folder:


So you will need to create the directory is it doesn't exist, and then CHMOD the directory in question to have permissions something like 755 or 775 depending on how your Apache is configured. You don't want to CHMOD it 777... you never want to do that.

You can usually set permissions via FTP programs or SFTP... but it can always be done from SSH or Telnet :)

And yes, I realise that 664 is probably a better chmod... but you know... some servers I've been on are just lovely and hardened and prevent writing withour very specific chmod values... 755 and 775 being the most common two... so I was being lazy in giving execute too as this prevents people bugging me about something unrelated to the hack ;)

Paul M 09-26-2004 02:58 PM

The full version screws up nicely formatted posts when you edit them, so I have used the "lite" version which doesn't do this.

buro9 09-26-2004 04:14 PM

Quote:

Originally Posted by Paul M
The full version screws up nicely formatted posts when you edit them, so I have used the "lite" version which doesn't do this.

Yes, I think I'll switch them around and suggest the lite version for all... and then those who want the aggressive version can opt for that if they wish.

AlexanderT 09-27-2004 06:29 AM

Quote:

Originally Posted by buro9
On average I've been witnessing it strip about 8% of total page bytes from every generated page.

We all GZIP don't we? The benefits of this is that all gaps between HTML become the same pattern, and so they compress better for GZIP'ing.

David, can you show me examples of your findings? I generally don't believe that the compression ratio is that much affected by the mere presence of whitespace. But of course I could be wrong ;)

buro9 09-27-2004 07:57 AM

Quote:

Originally Posted by AlexanderT
David, can you show me examples of your findings? I generally don't believe that the compression ratio is that much affected by the mere presence of whitespace. But of course I could be wrong ;)

Hehe, that was a nice challenge, but one I enjoyed.

To offer a proof I've done the following:
wget my forum index.php both compressed using the now default non-aggressive regexp, and also without this hack applied.

The sizes of the two files:
37,732 bytes = Compressed file
41,348 bytes = Uncompressed file

A 9% reduction in filesize.

I then ran gzip from within SSH, this should be the same as PHP gzip'ing them or a close approximation thereof:

6,748 bytes = Compressed + GZIP
8,102 bytes = Uncompressed + GZIP

A 20% reduction in final filesize.

The additional reduction of the size is higher than merely the white space being stripped and is an indicator that doing this does offer a benefit to GZIP.

So the compressed page (exactly the same HTML but without white space) ends up being 20% lighter with GZIP'ing than the non-compressed page.

Of course, the mileage varies on every page and with each style that you use. I should point out that the above was run against my current forum homepage which is not the default vBulletin style and that I've hacked my page quite a lot. So the filesize of your page and the amount it compresses and the amount it GZIPs are all factors depending on your configuration and the amount of whitespace in a page, etc.

The worst I've seen from this hack is a mere 3% reduction in file size on some of the smaller pages (such as the error messages).

The biggest benefit isn't the saved 1k of traffic... but the speed at which the rendering increases. Whether that is because the file transfered quicker, of the DHTML engine didn't have to work so hard ignoring whitespace, etc... I simply do not know... but it does appear to render faster and that is my prime goal :)

buro9 09-27-2004 08:23 AM

Of course... all of the above is simply a bigger advert for turning on GZIP than using this hack ;)

If anyone doesn't have GZIP turned on in their vBulletin... I suggest you do that first :)

AlexanderT 09-27-2004 02:22 PM

Ok, convinced. Thanks ;)

Jolten 09-28-2004 12:50 AM

Unfortunately, this will also strip white space when editing posts. That's NOT good.

buro9 09-28-2004 01:33 PM

Quote:

Originally Posted by Jolten
Unfortunately, this will also strip white space when editing posts. That's NOT good.

This is indeed true.

However the basic non-aggressive one will one strip excess space between ">" and "<".

Unless you have HTML in your posts this shouldn't matter.

Does this impact anything? Such as the WYSIWYG editor? I've been running it for a little while on my site and I haven't noticed any detrimental effects when editing posts.

If you can give a detailed example I'll have a look and see what can be done about it.

My site runs with a history of all edits (an edit log), so I can diff between changes to see how this effects it.

dethfire 09-28-2004 02:47 PM

this lowered my homepage size by 3kb, it's a quick hack so worth the small effot :)

Jolten 09-28-2004 03:41 PM

Essentially it strips all returns out of posts when editing. In general, it's not a big issue but for long posts it's a little tiresome to have to go insert returns again. I did have the more aggressive version installed. I'll try the lesser one and see if that helps a little.

Paul M 09-28-2004 04:04 PM

Quote:

Originally Posted by Jolten
Essentially it strips all returns out of posts when editing. In general, it's not a big issue but for long posts it's a little tiresome to have to go insert returns again. I did have the more aggressive version installed. I'll try the lesser one and see if that helps a little.

Quote:

Originally Posted by Paul M
The full version screws up nicely formatted posts when you edit them, so I have used the "lite" version which doesn't do this.

... :)

HuangA 09-28-2004 04:28 PM

This hack have a good concept; but it is not the best way to preserve bandwidth...

For example; if your site is not webmaster oriented, your members will be unlikely to post as much HTML/other contents that needs trimming, thus it wouldn't affect your site as much. If your site is webmaster oriented, you will want to preserve the code the way it is (for demonstration and code representation purpose). The members will have a hard time trying to learn:
Code:

<?
        if ( !$happy ) {
                print $sad_string;
        }
?>

if they don't know php and all they see is
Code:

<? if (!$happy){print $sad_string;}?>

And that's only a basic example, think what chaos it'd do with stuff like:
Code:

if (!$a):$b or die(print($c))
is presented to a newbie?

buro9 09-28-2004 07:43 PM

Oh absolutely.

But bandwidth preservation wasn't the #1 priority... delivery to the rendering engine and reduction of work for the rendering engine was.

If you have a site that is going to use CODE tags, etc... then use the now defaulted 'lite' version.

For those of you who do not post code, etc in CODE tags, and care not for <pre> tags... then the aggressive version will suit your needs and save a few more spaces.

buro9 09-28-2004 07:45 PM

And if you want to save bandwidth:
* Turn on GZIP
* Remove images where you consider them excess
* look at removing any redundent tags in the templates... you optimise the HTML ;)

Etc.

Removing a few images will do more than this does... but this will help it display faster ;)

Mickie D 09-29-2004 10:46 AM

for those having problems with the edit posts and new threads posts, PMS etc etc i have made this little addition that will switch to the light version if you view them pages (i think it works lol)

PHP Code:

    $thisscriptis = array(
        
'editpost',
        
'register',
        
'newreply',
        
'newthread',
        
'sendmessage'
    
);

    if (!
in_array(THIS_SCRIPT$thisscriptis))
    {
        
$patterns = array('/\>\s+\</''/^\s*/m');
        
$replace = array('> <''');
        
$vartext preg_replace($patterns$replace$vartext);
    }
    else
    {
        
$vartext preg_replace('/\>\s+\</''> <'$vartext);
    } 

thanks to mystic for the code fix i forgot to add


i wrote that out really quick so sorry if its not coded proppa but you get the idea ;)

h75 10-02-2004 03:46 AM

I clicked Install !!!!!!!!!!!!! terrific! :laugh: :banana:

Mystics 10-03-2004 04:58 PM

Quote:

Originally Posted by Mickie D
(i think it works lol)

Better change it to this:
Code:

        $thisscriptis = array(
                'editpost',
                'register',
                'newreply',
                'newthread',
                'sendmessage'
        );

        if (!in_array(THIS_SCRIPT, $thisscriptis))
        {
                $patterns = array('/\>\s+\</', '/^\s*/m');
                $replace = array('> <', '');
                $vartext = preg_replace($patterns, $replace, $vartext);
        }
        else
        {
                $vartext = preg_replace('/\>\s+\</', '> <', $vartext);
        }

:)

Mickie D 10-11-2004 01:00 PM

yeah mystics is right i did change it on my site and forgot to change it on here i will update that post :)

Mosh 10-17-2004 01:12 AM

[high]* Mosh clicks install (Mystics version)
[/high]

But credits to buro9 too, for getting me to read the entire thread through in the 1st place as it is a very interesting way of speeding things up.

JD :)

SaN-DeeP 10-17-2004 06:44 AM

/me installs.
I can see the difference, page loads faster for me

Thankx for this great 1 line hack

REgards,

Mickie D 10-17-2004 08:28 AM

Quote:

Originally Posted by jdsinclair
[high]* jdsinclair clicks install (Mystics version)
[/high]

But credits to buro9 too, for getting me to read the entire thread through in the 1st place as it is a very interesting way of speeding things up.

JD :)

dont you mean Mickie D's version ?

never mind i guess me thinking up the whole THIS_SCRIPT idea dont count and i already had the fix on my site i just forgot to update here :(

but as always thanks for mystics pointing it out to everyone else.

last but not least you wll also want to add private into the array so it does not screw up private messages

find
Code:

'editpost',
under it add
Code:

'private',
Regards
Mickie D

GlitterKill 10-18-2004 01:19 AM

Very nice! forum pages are noticably snappier.

Can this be implemented on other non VB php pages? How would that be done? I'm sure the rest of my site could benefit from this. :)

*installed*

Makador 10-18-2004 02:53 PM

Great! Thank you very much.

gwhooooey 10-18-2004 10:09 PM

I've got https://vborg.vbsupport.ru/showthread.php?t=62173 installed

...which splits up the two bits of line that you say to add the code before... so can you look at this hack and then tell me where i'd put your code. Thanks

Mosh 10-19-2004 11:13 AM

Quote:

Originally Posted by Mickie D
dont you mean Mickie D's version ?

never mind i guess me thinking up the whole THIS_SCRIPT idea dont count and i already had the fix on my site i just forgot to update here :(

but as always thanks for mystics pointing it out to everyone else.

last but not least you wll also want to add private into the array so it does not screw up private messages

find
Code:

'editpost',
under it add
Code:

'private',
Regards
Mickie D


Hehehehe, hey thanked Mystics because it was his exact code I used :)

Thank you also Mickie D, cause I am now going to add the 'private', line to it. :)

JD :)

MickDoneDee 10-19-2004 12:02 PM

Quote:

Originally Posted by gwhooooey
I've got https://vborg.vbsupport.ru/showthread.php?t=62173 installed

...which splits up the two bits of line that you say to add the code before... so can you look at this hack and then tell me where i'd put your code. Thanks

Does this post help?


All times are GMT. The time now is 10:08 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01453 seconds
  • Memory Usage 1,863KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_code_printable
  • (6)bbcode_php_printable
  • (19)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete