View Single Post
  #108  
Old 11-28-2012, 04:56 PM
moustafa moustafa is offline
 
Join Date: Oct 2008
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by final kaoss View Post
Well for those of you using vb supercharged, I've managed to make it load async which means even faster!

Go to your AdminCP --> Plugins & Products --> Plugin Manager

Find Product vB4: SuperCharged

Open JS Optimiser

Replace all of the code in there with this, then save.

Code:
if($vbulletin->options['vbsc_js_enable'] == 1){

      $c_vbsc = file_exists(DIR."/clientscript/vbsc.js");
      $c_vbscsize = $c_vbsc && filesize(DIR."/clientscript/vbsc.js") > 10;
      $c_global = $c_vbsc && filemtime(DIR."/clientscript/vbulletin-core.js") < filemtime(DIR."/clientscript/vbsc.js");
      
    if((!$c_vbsc || !$c_vbscsize || !$c_global) && $vbulletin->options['vbsc_js_common'] == 1){
        
        $err = "<strong style='font-size:13px;background-color:#000;padding:5px;color:#ff9000;font-weight:bold;text-align:center;width:100%;display:block;'>";
        if(!$c_vbsc){
            $err .= "The file ".DIR."/clientscript/vbsc.js is missing. Ensure the file exists (download and extract vbsc.zip again if not) and that you have the file chmodded as per the installation instructions, then run the Compress Javascript under vB4: SuperCharged in your Admin CP. Report any errors you encounter when running Compress Javascript.<br /><br />";
        } else if(!$c_vbscsize){
            $err .= "The file ".DIR."/clientscript/vbsc.js is empty. Ensure you have the file chmodded as per the installation instructions and run the Compress Javascript under vB4: SuperCharged in your Admin CP. Report any errors you encounter when running Compress Javascript.<br /><br />";
        } else if(!$c_global){
            $err .= "The ".DIR."/clientscript/vbsc.js cache has a modification time of before ".DIR."/clientscript/vbulletin-core.js. Your cache is almost certainly out of date. Please run Compress Javascript under vB4: SuperCharged in your Admin CP.<br />If you recently updated vBulletin, you should of course run Compress CSS also :) <br />";
        }
        $err .= "To prevent issues, your forum is currently running without optimised Javascript as a fallback.<br /><br />As a last resort if you cannot get this message to disappear, disable the Javascript Optimiser.</strong>";
        $output = $err.$output;
        
    } else {
        
        /*function vbsc_removejs($var){
            //return strpos($var, "threadlist") === false;
            return true;
        }*/
        
        //eval($vbulletin->options['vbsc_js_files']);
        //$GLOBALS['js_files'] = array_filter($GLOBALS['js_files'], 'vbsc_removejs');
require_once (DIR . '/includes/vbsc_global.php');
        $GLOBALS['js_uncached'] = '';
        

        function in_arrayi( $needle, $haystack ) {
            $found = false;
            foreach( $haystack as $value ) {
                if( strtolower( $value ) == strtolower( $needle ) ) {
                    $found = true;
                }
            }   
            return $found;
        } 
        
        function vbsc_jsleave($match){
            return (/*stripos($match, "FeatureLoader.js.php") !== false ||*/ stripos($match, "google_ad") !== false || stripos($match, "show_ad") !== false || stripos($match, "_google") !== false || stripos($match, "recaptcha") !== false/* || strpos($match, "treeview.css") !== false || strpos($match, "initVbTreeMenus") !== false || strpos($match, "treeview-min.js") !== false || strpos($match, "SHOW_ALL_TREE_ELEMENTS_THRESHOLD") !== false*/);
        }
        
        function vbsc_jsinline($matches){
            
            /*if(strpos($matches[0], "google_ad") !== false || strpos($matches[0], "show_ad") !== false){
                return $matches[0];
            }*/
            
            // workaround for cms sections and pm new window thing
            if(stripos($matches[0], "loadVbCss") === false && stripos($matches[0], "getBaseUrl") === false){
                if(vbsc_jsleave($matches[0]))
                    return $matches[0];
                    
                // whitelist specific terms, otherwise leave the javascript where it is as it's likely an embedded script such as ads, custom search etc.
                if(stripos($matches[0], "YAHOO") === false && stripos($matches[0], "vbulletin") === false && stripos($matches[0], "forum") === false && stripos($matches[0], "vbphrase") === false && stripos($matches[0], "vB_") === false && stripos($matches[0], "inlinemod") === false && stripos($matches[0], "vbseo") === false && stripos($matches[0], "vsa") === false)
                    return $matches[0];
            }
            
            
            if(strpos($matches[0], "SESSIONURL =") === false){
                $GLOBALS['js_uncached'] .= $matches[0];
                return '';
            } else {
                return $matches[0];
            }
        }
        //var_dump($GLOBALS["js_files"]);
        
        function vbsc_jscached($matches){
            global $vbulletin;
            //var_dump($matches);
            //$ret = "";
            //var_dump($matches);
            if(in_arrayi($matches[2], $GLOBALS["js_files"]) && strpos($matches[1], "<!--") === false && $vbulletin->options['vbsc_js_common'] == 1){
                //return "";
            } else {
                //return $matches[0];
                $GLOBALS["js_uncached"] .= $matches[0];
                
                if(strpos($matches[1], "<!--") !== false){
                    // handle IE conditional comments and normal comments
                    if(strpos($matches[1], "[if ") === false){                
                        $GLOBALS["js_uncached"] .= " -->";
                    } else {
                        $GLOBALS["js_uncached"] .= " <![endif]-->";
                    }
                }
                    
            }
            
            if(vbsc_jsleave($matches[0]))
                return $matches[0];
            
            
            
            //return strpos($matches[1], "if") !== false ? $matches[1] : $ret;
            // leave original comment opener in place as closing comment is not covered by the regex 
            return $matches[1];
        }
        
        $output = str_replace(array("<!-- Editor Scripts -->", "<!-- scripts for quick reply and quick edit -->", "<!-- / ajax errors table -->", "<!-- ajax errors table -->", "<!-- lightbox scripts -->
", "<!-- / lightbox scripts -->"), "", $output);
        
        //type="text\/javascript" 
        // handle potentially cached vBulletin javascript code
        $output = preg_replace_callback('/(<!--.*?]>\s+)?<script [^>]*?src=".*?clientscript\/([^?"]+).*?">\s*?<\/script>?/i', 'vbsc_jscached', $output);
        
        // handle YUI treeview code amongst other things
        $output = preg_replace_callback('/<script[^>]*?type=[\'"]text\/javascript[\'"] src="http:\/\/yui.yahooapis.com\/.*?">\s*?<\/script>/is', 'vbsc_jsinline', $output);

        // handle inline javascript code
        $output = preg_replace_callback('/<script[^>]*?type=[\'"]text\/javascript[\'"]>.*?<\/script>/is', 'vbsc_jsinline', $output);
        
        $readyfix = "";
        if($vbulletin->options['vbsc_js_common'] != 1){
            $readyfix = '<script type="text/javascript">YAHOO.util.Event.onDOMReady(function() {if(YAHOO.vBulletin.vB_XHTML_Ready) return; console.log("Fire vB_XHTML_Ready");vB_XHTML_Ready.fire();YAHOO.vBulletin.vB_XHTML_Ready = true;});</script>';
        }
       
        // append vbsc.js
        $output = preg_replace('/(<\/body>)/i', ($vbulletin->options['vbsc_js_common'] == 1 ? '<script type="text/javascript" src="clientscript/vbsc.js" async="async"></script>' : '').$GLOBALS["js_uncached"].$readyfix.'$1', $output, 1);
        
        


        //$output = preg_replace('/<script type="text\/javascript">\s+<!--\s+\/\/ Main vBulletin Javascript Initialization/', '<script type="text/javascript" src="/clientscript/vbsc.js"></script>'.$GLOBALS["js_uncached"].'$1', $output, 1);

        //$output = str_replace('SECURITYTOKEN', 'vbsc_SECURITYTOKEN', $output);    
    }
}
It will now defer the parsing of the vbsc.js file, saving a few hundred KB and increasing your page load time!

Kindly tell me where to find the JS Optimiser.

Thanks.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01238 seconds
  • Memory Usage 1,822KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete