vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Realtime Template Compressor: Reduces page sizes, loads pages faster, saves bandwidth (https://vborg.vbsupport.ru/showthread.php?t=83248)

Guest210212002 01-23-2006 03:17 PM

Quote:

Originally Posted by ryuji
i meant in your templates... you can remove all the spaces but on my templates it removed code it wasnt supposed to when i did that, best way is to download the whole style and then use a find and replace to add a space to all of them

So are you saying that if I have:

Code:

<!--This is my comment-->
That I need to change them to:

Code:

<!-- This is my comment -->
Like that?

ryuji 01-23-2006 04:51 PM

thats all i had to do.. and it solved issues with the scripts

Hellcat 01-25-2006 12:30 AM

I played around with this a bit :)
And after talking to my co-admin (who has quite some knownledge of regular expressions) he told me to exclude <script> and other tag blocks is not possible with one RegEx, it would need additional code.

Well, so I started making some code :)

This I what I currently have, it gave me a "compression" ratio vom ~10% to ~15% in my tests, while leaving user input, [code] posts and JS fully intact (so far ;))

I added some comments, so you can see what is done where :)

PHP Code:

global $ascript$atext$apre;

// definition of callback functions
function cb_script($matches)
{
  global 
$ascript;

  
$i count($ascript) + 1;
  
$h md5($matches[0]);
  
$ascript[$i][0] = $matches[0];
  
$ascript[$i][1] = $h;

  return 
$h;
}

function 
cb_text($matches)
{
  global 
$atext;

  
$i count($atext) + 1;
  
$h md5($matches[0]);
  
$atext[$i][0] = $matches[0];
  
$atext[$i][1] = $h;

  return 
$h;
}

function 
cb_pre($matches)
{
  global 
$apre;

  
$i count($apre) + 1;
  
$h md5($matches[0]);
  
$apre[$i][0] = $matches[0];
  
$apre[$i][1] = $h;

  return 
$h;
}


// init some variables/arrays
$page_byte=strlen($output);
$ascript = array();
$atext   = array();
$apre    = array();

// cut from output, and store away for later re-inclusion, everything between <textarea> and <pre> tags
// (we do not want to touch those blocks as they may contain wanted whitespace)
$output=preg_replace_callback('/<textarea.*?[^\btextarea>\b]*?textarea>/si'"cb_text"$output);
$output=preg_replace_callback('/<pre.*?[^\bpre>\b]*?pre>/si'"cb_pre"$output);

// strip all whitespace at the beginning of every new line (but leave the linebreak intact)
$output=preg_replace('/\r\n(\s*)/'"\n"$output);

// cut from output, and store away for later re-inclusion, everthing between <script> tags
// (we don't want to strip the linebreaks from script code since that would render the scripts non working)
$output=preg_replace_callback('/<script.*?[^\bscript>\b]*?script>/si'"cb_script"$output);

// strip all linebreaks and HTML-Comments from the output
// (since we first strip all linebreaks, even multi-line comments will get striped this way! :-))
$output str_replace"\n" "" $output );
$output=preg_replace('/<!-- .*? -->/'""$output);

// re-insert everything we saved before
foreach ( $ascript as $block)
{
  
$output str_replace$block[1] , $block[0] , $output );
}
foreach ( 
$atext as $block)
{
  
$output str_replace$block[1] , $block[0] , $output );
}
foreach ( 
$apre as $block)
{
  
$output str_replace$block[1] , $block[0] , $output );
}

// calculate some nice looking numbers :-)
$pagenew_byte=strlen($output);
$page_kilobyte=number_format(($page_byte/1024),2);
$pagenew_kilobyte=number_format(($pagenew_byte/1024),2);
$pagesaved_byte=$page_byte-$pagenew_byte;
$pagesaved_kilobyte=number_format((($pagesaved_byte)/1024),2);
$pagesaved_perc=number_format(((100*$pagesaved_byte)/$page_byte),2);

// and add the compression stats at the very bottom of the page
$output str_replace('</body>''<center><span class="smallfont">[<em>page compression: </em>' $pagenew_kilobyte 'k/' $page_kilobyte 'k (<strong>' $pagesaved_perc '%</strong>)]</span></center></body>'$output); 


Guest210212002 01-25-2006 01:00 AM

That fixed the advanced mode bug, Hellcat, but hosed tons of other stuff on my forums. For one, the edit/quote buttons at the bottom right of posts were almost overlapped, and the breadcrumbs had no spacing at all.

A step in the right direction though, to be sure.

Screenshot attached of what I'm experiencing. I'd LOVE to get this sorted out - your code, albeit buggy on my particular theme, quadrupled my compression savings.

Guest210212002 01-25-2006 01:02 AM

For reference, a screeny of my forums using my existing code, which only strips comments.

Hellcat 01-25-2006 01:49 AM

Hmm.... I think I know what that might cause....
If that's it it would reduce the ratio, but increase compatibility....
[high]* Hellcat starts tweaking :)
[/high]

[EDIT]
OK, try this:

In my above posted code, find theese two lines:
Code:

$output = str_replace( "\n" , "" , $output );
$output=preg_replace('/<!-- .*? -->/', "", $output);

and replace them by those:
Code:

$output = str_replace( "\n" , " " , $output );
$output = preg_replace('/<!--[^\{]*?-->/', "", $output);

Like I already said, this drops the ratio a bit again, but should raise compatibility.
At least I could confirm this in my last tests....

[high]* Hellcat waits for feedback now :)[/high]

The Chief 01-25-2006 02:29 AM

does this work with vB Drupal?

Hellcat 01-25-2006 02:32 AM

Quote:

Originally Posted by gamebgs
does this work with vB Drupal?

Hmm, can't test that since I don't have that installed.
There's only one way to find out ;)

But it should, yes....

The Chief 01-25-2006 02:36 AM

Quote:

Originally Posted by Hellcat
Hmm, can't test that since I don't have that installed.
There's only one way to find out ;)

But it should, yes....

I'll try that right now ;)

is it supposed to take all the lines away from the source?

The Chief 01-25-2006 02:39 AM

and the result is: Nope it doesn't work with vb drupal...

works fine for my forums though so installed...

/me clicks install

ryuji 01-25-2006 03:16 AM

hellcat should make a new one since the original writer poof'd long ago, i will try it on my boards later on durring the week

Hellcat 01-25-2006 03:28 AM

Quote:

Originally Posted by gamebgs
is it supposed to take all the lines away from the source?

It strips all whitespace and linebreaks.
Except in JS and some other blocks.


Quote:

Originally Posted by gamebgs
and the result is: Nope it doesn't work with vb drupal...

works fine for my forums though so installed...

[high]* gamebgs clicks install[/high]

What doesn't work?
What are the effects?


Quote:

Originally Posted by ryuji
hellcat should make a new one since the original writer poof'd long ago, i will try it on my boards later on durring the week

Since the last edit it doesn't even contain one single line of the original code :D
Well, besides the % calculation for the footer stats, but I'm going to change this as well in a way that you can place that stats display wherever you like (or hide it).


[EDIT]
How about something like this:
(this is a real shot, and actually works already, no fake ;))
http://files.area-42.net/060124/pgcmprcpshot.gif

The stats makeup itself is now stored in a template and no longer hard-coded - so you can not only place the thing where ever you like you can also easiely customize it :cool:

klaush 01-25-2006 07:19 AM

Just to keep informed....

klaush 01-25-2006 07:21 AM

Quote:

Originally Posted by Hellcat
Hmm.... I think I know what that might cause....
If that's it it would reduce the ratio, but increase compatibility....
[high]* Hellcat starts tweaking :)
[/high]

Looks fine on a 3.5.2.

Thanks!

The Chief 01-25-2006 12:36 PM

It doesn't do anything, thats the problem, it doesn't seem to affect it...

Guest210212002 01-25-2006 02:36 PM

Quote:

Originally Posted by Hellcat
Hmm.... I think I know what that might cause....
If that's it it would reduce the ratio, but increase compatibility....
[high]* Hellcat starts tweaking :)
[/high]

[high]* Hellcat waits for feedback now :)[/high]

That fixed all of the display problems that I was having, and the advanced editor bug.

So far, that seems to be 100% working on 3.5.3. Thank you VERY much for the effort Hellcat, you've made this mod usable again for tons of us. :D

[high]* Guest210212002 cheers
[/high]

Argh: It breaks the actual player portion of this hack, however, but that's the only thing I can find.

This is the code that goes away with the latest:

Code:


                <object data="http://www.sevenstring.org/forum/players/mp3player.swf?file=http%3A%2F%2Fwww.chrisquigley.com%2Faudio%2Fmidwinter.mp3&amp;autoPlay=false" type="application/x-shockwave-flash" width="400" height="20" class="player_mozilla">
                  <param name="play" value="true" />
                  <param name="wmode" value="opaque" />
                  <param name="quality" value="high" />
                </object>
                <!--[if IE]>
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="20">
                  <param name="movie" value="http://www.sevenstring.org/forum/players/mp3player.swf?file=http%3A%2F%2Fwww.chrisquigley.com%2Faudio%2Fmidwinter.mp3&amp;autoPlay=false" />
                  <param name="play" value="true" />
                  <param name="wmode" value="opaque" />
                  <param name="quality" value="high" />
                </object>
                <![endif]-->


EricaJoy 01-25-2006 07:05 PM

so do I just replace the code in the XML with Hellcats code for this?

dethfire 01-25-2006 07:30 PM

great work hellcat, you've fixed the bug and doubled my optimization

Hellcat 01-25-2006 08:47 PM

Quote:

Originally Posted by princessfrozen
so do I just replace the code in the XML with Hellcats code for this?

I'm going to release a product .XML this night of my version that also holds some more features (like AdminCP integration, stats can be fully customized....).

You'll then just to have to import that XML and you're set :)

The Chief 01-25-2006 09:04 PM

Quote:

Originally Posted by Hellcat
I'm going to release a product .XML this night of my version that also holds some more features (like AdminCP integration, stats can be fully customized....).

You'll then just to have to import that XML and you're set :)

did you try it with vB Drupal, as it doesn't seem to do anything for me...

Megareus Rex 01-25-2006 09:51 PM

How would I go about changing where this appears? (unlike the microstats one, I actually looked this time >.>

I'd like it under the microstats (which are now under the copyright), but I don't see how to do it.

Smiry Kin's 01-25-2006 10:23 PM

Quote:

Originally Posted by Smiry Kin's
with 3.5.2

and element skil.

it messes up the DHTML thing.. which is a pain really.. any way to sort this?

anyhelp?

EricaJoy 01-25-2006 11:00 PM

Quote:

Originally Posted by Hellcat
I'm going to release a product .XML this night of my version that also holds some more features (like AdminCP integration, stats can be fully customized....).

You'll then just to have to import that XML and you're set :)

woot! can't wait!

Guest210212002 01-25-2006 11:16 PM

Quote:

Originally Posted by Hellcat
I'm going to release a product .XML this night of my version that also holds some more features (like AdminCP integration, stats can be fully customized....).

You'll then just to have to import that XML and you're set :)

Sweeeet. :D

If you can make it not break that media code snippet, I will fedex you a puppy!*


*this is a lie

Hellcat 01-25-2006 11:47 PM

@all:
My version:
https://vborg.vbsupport.ru/showthread.php?t=106333 :cool:

For the "how to customize":
You have the option to use a special HTML tag (<cmpstat />) that will show the stats on the place where you inserted this tag when that option is enabled.
You can further customize the look of it by editing the template.
(more details in the readme :))

@gamebgs:
Hmm, I'll take a look a that Drupal issue.
Drupal is freely available from here, so I can install it for testing, right?

@Chris-777:
I will look at this as well :)

BillP 02-15-2006 08:24 PM

I installed this hack, and my site is small, but I would think that doing a preg_replace on every page load would be a waste of CPU if your site was heavily loaded.

I think a more important hack or plugin would be to do the following:
  1. Catch and eliminate wasted whitespace on post creation instead of on display
  2. Catch wasted white space in templates on creation instead of on display
  3. Maintenence items to go clean up white space in old posts and templates (run once)

This way you get the CPU hit only on posting, the size of the posts in the database goes down a little bit, which further reduces load on the DB server.

LiveMicSociety 03-08-2006 04:08 PM

Installed :up:

MissKalunji 03-08-2006 04:43 PM

is it workign fine? does it really speed up the pages?

MissKalunji 03-08-2006 04:44 PM

oops wrong thread

Citizen 03-24-2006 02:14 PM

I know that this hack decreases the bandwidth load, but does it increase or decrease the processor load?

MissKalunji 03-24-2006 03:26 PM

Quote:

Originally Posted by Citizen
I know that this hack decreases the bandwidth load, but does it increase or decrease the processor load?


Yes it does :)

dethfire 03-24-2006 03:32 PM

Quote:

Originally Posted by Citizen
I know that this hack decreases the bandwidth load, but does it increase or decrease the processor load?

it will increase the load a little, nothing major that I've seen

Citizen 03-24-2006 04:30 PM

I'm more worried about my processor load than bandwidth... I guess this hack isnt for me ;)

MissKalunji 03-24-2006 08:46 PM

Quote:

Originally Posted by dethfire
it will increase the load a little, nothing major that I've seen


how can it increase the loads? :surprised: if the pagess are reduces it should save up the load thats why it makes the page faster....

im using hellcats one and havent see no loads its even lower then it has ever been +accelerator etc

Zia 07-20-2006 09:04 AM

helo shining,

is there any upgrade gonna release for vb3.6.0 ??

wtrk 09-04-2006 02:54 PM

this hack is good, but causes alot of server load when the forum is busy. i had to remove it because of that.

bairy 09-16-2006 11:50 AM

Quote:

Originally Posted by MissKalunji
how can it increase the loads? :surprised: if the pagess are reduces it should save up the load thats why it makes the page faster....

Because it takes time and processing power to compress a template.
The pages are smaller in code, which means less for the surfer to download which means it appears quicker to them.

The only real benefit to this hack is saved bandwidth because I doubt the time saved in a smaller page download outweighs the time it takes to make it smaller.

sross 09-22-2006 04:22 AM

I'd like to see this mod rebuilt for 3.6 but instead of it compressing the template each time it loads how about this mod creates a duplicate of your style that is fully compressed, then you just use that style. if you have to change templates use your old style then recompress. Is this possible? and for 3.6.1 plz! :)

Fenriz 09-23-2006 03:59 PM

sross :up:

packetattack 09-26-2006 12:34 AM

So has anyone tested this under vB3.6?


All times are GMT. The time now is 08:26 PM.

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.01603 seconds
  • Memory Usage 1,874KB
  • 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
  • (5)bbcode_code_printable
  • (1)bbcode_php_printable
  • (17)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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