vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Compress Forum Templates (Speed up your Forums & Save Bandwidth) (https://vborg.vbsupport.ru/showthread.php?t=79923)

Trigunflame 04-13-2005 10:00 PM

Compress Forum Templates (Speed up your Forums & Save Bandwidth)
 
Compress Forum Templates & Phrases
Speed up your Forums & Save Bandwidth


Description:

Hi, this is a pretty simple hack that involves compressing the 'compiled' version of your templates, this way it only compresses the part thats to be shown on the forum and not the actual template data you edit.

Background:

Got the idea from Zero Tolerance in buro9's thread:
https://vborg.vbsupport.ru/showthread.php?t=69787

The above hack compresses the page at parse time, while it provides some speed enhancement, on large pages you can actually "negate" the point of using the hack in the first place, because of the overhead in compression.

Thus, the creation of this hack is to provide similiar functionality, but done in the adminCP; and without the overhead of constant compression.

Info:

No Queries. Only query is used when compressing your templates, the rest of the time its just pulling the templates straight out of the database like normal.

Updates:

Version 2.8 - Added Strip Whitespace from Start of JS Line by buro9
Version 2.7 - Option to strip HTML Comments from Compressed Output
Version 2.6 - Removed Phrase Compression altogether, Too Iffy
Version 2.5 - Removed the ASCII \n removal, emails should work now.
Version 2.4 - Had to add editor_jsoptions_size to the Bad Templates array, it also was causing a font selection error.
Version 2.3 - Added Phrase compression support, should help further increase page compression.
Version 2.2 - Slightly Recoded Template compression for faster results.
Version 2.1 - Added php_include templates to bad templates, will not compress these.
Version 2.0 - Recoded Script, added support for certain templates to not compress
Version 1.9 - Re-Added support for InLine Styles.
Version 1.8 - Removed support for InLine Styles, all Style data is left with Linebreaks.
Version 1.7 - Removed support for InLine Javascript, all JavaScript is left with Linebreaks.
Version 1.6 - Fixed Tab problem, tabs are replaced with a single space
Version 1.5 - Removed a part of the SQL.
Version 1.4 - TOTALLY Remade, Works perfect now; Ultimate Compression
Version 1.3 - Adjusted Again
Version 1.2 - Adjusted Stripping regex
Version 1.1 - Added Uncompress Support
Version 1.0 - Release

Install:

Step 1. [ Open admincp/template.php ]
Step 2. [ Go to about line: 1278, or just look for $_REQUEST['do'] == 'edit' ]
Step 3. [ Above Step 2, add the below code ]

PHP Code:

// #############################################################################
// Rebuild Templates Compressed
if ($_REQUEST['do'] == 'compressall')
{
    
/**
     * Compress Templates Mod
     *
     * Thanks for Idea From Zero Tolerance.
     * Thanks for Help & Support From buro9
     *
     * @author Trigunflame
     * @version 2.8
     * @copyright Dusty Burns, 2005-2006
     */

    // Strip Comments?
    // Use true or false
    
$stripComments true;

    
// Search & Replace
    
$search  = array('/\s+/''/\t+/'); 
    
$replace ' '
    
$jsearch  = array('/^\s+/''/\t+/');
    
$jreplace = array(''' ');
    
    
// Strip Comments
    
if ($stripComments) { $search[] = '/<!--.*?-->/'; }
    
    
// List of Templates to NOT Compress
    
$badTemplates = array(
        
'editor_jsoptions_font',
        
'editor_jsoptions_size',
        
'phpinclude_start',
        
'phpinclude_end'
    
);
            
    
// Get Modified Templates
    
$templates $DB_site->query(
        
"SELECT templateid, title, template_un " 
        
"FROM " TABLE_PREFIX "template " .
        
"WHERE template_un <> '' "
    
);
    
    
// Selectively Compress
    
while ($template $DB_site->fetch_array($templates))
    {
        
// Compile Template
        
$compiledTemplate compile_template($template['template_un']);
        
        
// Bad Template
        
if (in_array(strtolower($template['title']), $badTemplates))
        {
            
// Ignoring Template
            
echo "Bad Template [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
$compressedTemplate $compiledTemplate;
        }
        
        
// Reverting Template
        
else if ($_REQUEST['revert'])
        {
            
// Uncompressing
            
echo "Uncompressing [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
$compressedTemplate $compiledTemplate;
        }
        
        
// Good Template
        
else
        {
            
// Compressing
            
echo "Compressing [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
// Get All Lines
            
$compiledTemplate preg_split('(\r\n|\r|\n)'$compiledTemplate);
            
            
// Javascript Status
            
$js false;

            
// Compressed Output
            
$compressedTemplate '';
            
            
// Loop Lines
            
foreach ($compiledTemplate AS $line)
            {
                
// LowerCase Line
                
$lowerLine strtolower($line);
                
                
// Look For Start of JavaScript
                
if (strpos($lowerLine'<script') !== false) { $js true; }
                
                
// Check For Null
                
if (trim($line) == '') continue;
    
                
// Check JS Status
                
if (!$js && !$st)
                {
                    
// Full WhiteSpace Strip
                    
$line preg_replace($search$replace$line);
                }
                else
                {
                    
// Straight Output
                    
$line preg_replace($jsearch$jreplace$line) . "\r\n";
                }

                
// Look For End of JavaScript
                
if (strpos($lowerLine'</script>') !== false) { $js false; }
                
                
// Check For Null
                
if (trim($line) == '') continue;
                
                
// Append Line
                
$compressedTemplate .= $line;
            }
        }
        
        
// Update Template
        
$DB_site->query(
            
"UPDATE " TABLE_PREFIX "template " 
            
"SET template = '" addslashes($compressedTemplate) . "' " 
            
"WHERE templateid = '" $template['templateid'] . "'"
        
);
    }
    
    
// Redirect
    
print_cp_redirect('index.php?do=home'1);
    
    
/**
     * End Compress Templates Mod
     */


Step 4. [ close admincp/template.php and open admincp/index.php ]
Step 5. [ look for ]

PHP Code:

construct_nav_option($vbphrase['find_updated_templates'], 'template.php?do=findupdates''<br />'); 

Step 6. [ below this, add the code ]

PHP Code:

construct_nav_option("Compress Templates"'template.php?do=compressall''<br />');
construct_nav_option("Uncompress Templates"'template.php?do=compressall&revert=1''<br />'); 

How-To Run

1. Install
2. In the admincp left navigation, select "Compress Templates".
3. Repeat Step 2 after each modification of your Templates whenever you decide to change something.
4. If you want to uncompress all Templates, select "Uncompress Templates"
5. IF Any Templates Come Out Weird, add the template Name to the Bad Templates Array and Re-Run the Compress Templates.

Cyricx 04-14-2005 07:21 PM

So if I'm understanding you right..

The part the page loads has the spaces stripped, but when you edit the template in the admincp, it has all the spaces there for ease of navigating?

Would it be possible or would it help even more to strip out the html commenting?

DR?@M W?@V?R 04-14-2005 07:29 PM

I tryed this out and it gave me some javascript errors on showthread and the portal page. This might be just applying to my board however.

Luckly I downloaded a backup of my templates before I tryed it out.

Trigunflame 04-14-2005 07:40 PM

Quote:

Originally Posted by DR?@M W?@V?R
I tryed this out and it gave me some javascript errors on showthread and the portal page. This might be just applying to my board however.

Luckly I downloaded a backup of my templates before I tryed it out.

I don't get any errors on any of my pages :/

-----------

Ps. Re-Editing a template, resaves the normal version of it, so really you would only need to re-save a template that was causing the js errors. That or fix the JS.

Trigunflame 04-14-2005 07:41 PM

Quote:

Originally Posted by Cyricx
So if I'm understanding you right..

The part the page loads has the spaces stripped, but when you edit the template in the admincp, it has all the spaces there for ease of navigating?

Would it be possible or would it help even more to strip out the html commenting?

In the database, there are 2 fields were the template is stored as an editable copy, and a output copy.

This script just modifies the output copy, that way the editing copy is still easy to edit.

Trigunflame 04-14-2005 07:49 PM

Update:

Added support to uncompress all templates.

Trigunflame 04-14-2005 08:23 PM

Update:

Adjust the whitespace regex, might prevent javascript errors..

The Realist 04-14-2005 10:15 PM

I installed this hack but when I compress the templates my dropdown menu does not work. When I click it the page just shoots to the top of the screen?

Laters

Trigunflame 04-15-2005 03:03 AM

Quote:

Originally Posted by The Realist
I installed this hack but when I compress the templates my dropdown menu does not work. When I click it the page just shoots to the top of the screen?

Laters

Hmm this seems to be an IE problem, I get no errors whatsoever in firefox. IE for some reason doesnt like to "not" have, newlines in JS.

I redid the regex somewhat again, and it works; just not compressing as much as it used to; im gonna keep trying some different methods.

Cyricx 04-15-2005 11:41 AM

This weekend I'm refreshing my test site with the live site files, then I'll give this a healthy test run :)

Trigunflame 04-15-2005 12:57 PM

Quote:

Originally Posted by Cyricx
This weekend I'm refreshing my test site with the live site files, then I'll give this a healthy test run :)

Ya this modification is really experimental.. main reason I didn't go into large coding detail or write a very large documentation.

Although after the latest code change, I'm pretty sure it fixed the problem with JS.

buro9 04-15-2005 03:08 PM

Quote:

Originally Posted by Trigunflame
Ya this modification is really experimental.. main reason I didn't go into large coding detail or write a very large documentation.

Although after the latest code change, I'm pretty sure it fixed the problem with JS.

Very nice Trigunflame.

Negates the one I was working on for Zero Tolerence ;) (I'm stuck with a fried hard-drive so it's in limbo... so I really appreciate this being picked up by someone else :))

I'm actually going to install this myself... even though I wrote the compress hack :D

buro9 04-15-2005 03:36 PM

I've sent an update from my hack to let people know of yours.

I think it's a very valuable addition to any vBulletin admins arsenal of essential hacks :)

Trigunflame 04-15-2005 03:45 PM

Quote:

Originally Posted by buro9
I've sent an update from my hack to let people know of yours.

I think it's a very valuable addition to any vBulletin admins arsenal of essential hacks :)

Ya, unfortunately im not a master in REGEX, the compressing of the templates currently is not optimal in its design.

Since this is editing the actual parsed templates, one one regex needs to be written, not 2 like we are using now..

The problem lies within the JS tags, need to make one that removes whitespace AND tabs,newlines from every tag outside of <!-- // --> and <!-- -->, anything within those, retains its linebreaks and whitespace...

vulture 04-15-2005 03:52 PM

Quote:

Originally Posted by buro9
Very nice Trigunflame.

Negates the one I was working on for Zero Tolerence ;) (I'm stuck with a fried hard-drive so it's in limbo... so I really appreciate this being picked up by someone else :))

I'm actually going to install this myself... even though I wrote the compress hack :D


Can this be used alongside your hack?

Trigunflame 04-15-2005 03:53 PM

Quote:

Originally Posted by vulture
Can this be used alongside your hack?

There would be no point.

Trigunflame 04-15-2005 03:54 PM

Quote:

Originally Posted by buro9
Very nice Trigunflame.

Negates the one I was working on for Zero Tolerence ;) (I'm stuck with a fried hard-drive so it's in limbo... so I really appreciate this being picked up by someone else :))

I'm actually going to install this myself... even though I wrote the compress hack :D

Ya well as I posted above, the original REGEX I was using was not similiar to yours; however until I create one that does what I need i'll have to use it temporarily.

Corriewf 04-15-2005 06:52 PM

Isnt this adding a query?

Cyricx 04-15-2005 07:18 PM

It only runs the query when you compress the templates in the admincp. That step.

It doesn't add an additional query to any pages.

Corriewf 04-15-2005 07:34 PM

Does this work with other hacks that you know of?

Cyricx 04-15-2005 07:37 PM

I haven't tossed this onto my test site yet, but there isn't any hacks that would contradict this.

He's using add below/above rather then replace code, which is rockin and it's a total new function.

Nothing for it to clash with.

jcr 04-15-2005 07:53 PM

This hack is truly amazing, I really can feel, see and notice the difference!

Two thumbs up!

Highly recommendable!

diettalk 04-15-2005 09:20 PM

Added to my forum and it seems to be loading quicker here. My load average jumped up but it seems to be coming down.. probably just eaccelerator updating the cache.

Rambo 04-15-2005 11:43 PM

Hrm,

I think i can notice a slight difference with this installed, seem's to be working so far.

Good job

Trigunflame 04-16-2005 06:10 AM

Im almost done with an update guys, Im writing code to take care of the removing of whitespace.

Trigunflame 04-16-2005 07:15 AM

UPDATE:

Finished the new version, it works great.

Checks template line for line, removing any and all whitespace, tabs etc.. checked the result in IE/Firefox with NO Errors.

Script is made to go "around" the javascript, so its left in its natural state except the tabs.

Blam Forumz 04-16-2005 07:31 AM

This is brilliant! My forums are so much faster, thanks :D

Blam Forumz 04-16-2005 07:33 AM

Ok, I have a problem, I use this in my phpinclude_start:

Code:

switch(intval(time() / 2) % 4)
{
    case 0:
    $banner = '/designs/images/skin/boredom.gif';
    break;
    case 1:
    $banner = '/designs/images/skin/boredom1.gif';
    break;
    case 2:
    $banner = '/designs/images/skin/boredom2.gif';
    break;
    case 3:
    $banner = '/designs/images/skin/boredom3.gif';
    break;
}

and then i use $banner in my header, when I compress all templates the images dont appear, but when I uncompress them they do, any idea?

Trigunflame 04-16-2005 07:43 AM

Quote:

Originally Posted by Blam Forumz
Ok, I have a problem, I use this in my phpinclude_start:

Code:

switch(intval(time() / 2) % 4)
{
    case 0:
    $banner = '/designs/images/skin/boredom.gif';
    break;
    case 1:
    $banner = '/designs/images/skin/boredom1.gif';
    break;
    case 2:
    $banner = '/designs/images/skin/boredom2.gif';
    break;
    case 3:
    $banner = '/designs/images/skin/boredom3.gif';
    break;
}

and then i use $banner in my header, when I compress all templates the images dont appear, but when I uncompress them they do, any idea?

Im using this in mine: phpinclude_start

PHP Code:

$b = array(
  
'images/v4/banner01.jpg',
  
'images/v4/banner02.jpg'
);
$banner $b[array_rand($b)]; 

and my header is

Code:

<!-- logo -->
<a name="top"></a>
<center>
<table cellpadding='0' cellspacing='1' bgcolor='#C7C5BF' align='center' width="$stylevar[outertablewidth]">
<tr>
<td align='center' bgcolor='#F8F5F0'>
<table border="0" width='100%' cellpadding="0" cellspacing="0" align="center"><tr><td align="$stylevar[left]"><img src="$banner" border="0" alt="$vboptions[bbtitle]" /></td></tr></table>
<!-- /logo -->

<!-- content table -->
$spacer_open

$_phpinclude_output

It's working fine for me, maybe adjust yours to mine?

Blam Forumz 04-16-2005 07:52 AM

Nope, still doesnt work :(

Blam Forumz 04-16-2005 07:54 AM

it just displays my alt tag :(

Trigunflame 04-16-2005 08:52 AM

Quote:

Originally Posted by Blam Forumz
it just displays my alt tag :(

Update;

Contact with Blamz, fixed problem.

Notice;

Everyone, even if you have installed this hack. REINSTALL it with the latest code, it drastically changes some stuff that would cause errors otherwise..

jcr 04-16-2005 09:20 AM

New version installed, just one quickie before I do anything;

Should I uncompress before applying the new way to compress?

Edit:

One more thing, the reputation images gets very seperated after this hack :-/

Trigunflame 04-16-2005 09:28 AM

Quote:

Originally Posted by jcr
New version installed, just one quickie before I do anything;

Should I uncompress before applying the new way to compress?

Nah, everytime you select compression, its source is from the "editable" version of the templates.

In other words, everytime you select Compress Templates its compressing them freshly.

jcr 04-16-2005 09:30 AM

Quote:

Originally Posted by Trigunflame
Nah, everytime you select compression, its source is from the "editable" version of the templates.

In other words, everytime you select Compress Templates its compressing them freshly.

wow, great! :) Absolutely great! , See my other edited question also if you have time (about the reputation images), otherwise, thank you for a great hack, and fast support :)

Trigunflame 04-16-2005 09:36 AM

Quote:

Originally Posted by jcr
One more thing, the reputation images gets very seperated after this hack :-/

Mine does'nt :/

Try uncompress/compress, if that doesn't work, paste the html code of posts where this is affected, if I see what the html looks like I may can help you.

Almost post a screenshot.

Deimos 04-16-2005 09:39 AM

Works aok for me, not sure if I see much of a difference performance wise

Trigunflame 04-16-2005 09:40 AM

Quote:

Originally Posted by Deimos
Works aok for me, not sure if I see much of a difference performance wise

It has more of a bandwidth save than performance :)

If you use this in addition to gzip compression you will save roughly 50-60% in total bandwidth per page.

jcr 04-16-2005 09:43 AM

Quote:

Originally Posted by Trigunflame
Mine does'nt :/

Try uncompress/compress, if that doesn't work, paste the html code of posts where this is affected, if I see what the html looks like I may can help you.

Almost post a screenshot.

Okay hm, I have removed the reputation in the postbit, it is in the memberlist, things looks kinda strange over at my place.

Uncompressing, and then compressing again removed the whitespace between the reputation images :D

The Realist 04-16-2005 09:46 AM

This latest code does not work for me in IE, the one before worked ok. What Im getting now is my dropdown menues work ok but when I click the New Posts link nothing happens?

Owe well.


All times are GMT. The time now is 03:20 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.01533 seconds
  • Memory Usage 1,901KB
  • 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
  • (3)bbcode_code_printable
  • (4)bbcode_php_printable
  • (16)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