WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
how to Combine external CSS (2 posts)

  1. kletskater
    Member
    Posted 2 years ago #

    in order to improve page load time, I wonder how I can combine CSS with the help of WP SC
    I now get the notice of pingdom tools that:
    There are 5 CSS files served from http://www.mysite.nl. They should be combined into as few files as possible.

    http://www.mysite.nl/wp-content/plugins/bwp-minify/min/?f=wp-content/plugins/updated-today-plugin/styles.css,…
    http://www.mysite.nl/wp-content/plugins/count-per-day/counter.css
    http://www.mysite.nl/wp-content/plugins/dmsguestbook/dmsguestbook.css
    http://www.mysite.nl/wp-includes/js/thickbox/thickbox.css?1
    http://www.mysite.nl/wp-includes/js/thickbox/thickbox.css?ver=20111117

    the thickbox i don't even know what it's for(don't have such plugin

    http://wordpress.org/extend/plugins/wp-super-cache/

  2. Moreslides
    Member
    Posted 1 year ago #

    Good idea. Sorry about not doing that. Here's what I had to do.

    1) Since my server does not allow mod_deflate or mod_gzip, I had to compress the jsquery script with PHP. I created a file and placed it in my root directory called gzip.php. Within the file is this code:

    <?php
    ob_start ("ob_gzhandler");
    if( isset($_REQUEST['file']) ){
    $file = $_REQUEST['file'];
    if( goodfile($file) ){
    $ext = end(explode(".", $file));
    switch($ext){
    case 'css':$contenttype = 'css';break;
    case 'js':$contenttype = 'javascript';break;
    default:die();break;
    }
    header('Content-type: text/'.$contenttype.'; charset: UTF-8');
    header ("cache-control: must-revalidate");
    $offset = 60 * 60;
    $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
    header ($expire);
    $data = file_get_contents($file);
    $data = compress($data);
    echo $data;
    }
    }
    exit;
    function goodfile($file){
    $invalidChars=array("\\","\"",";",">","<",".php");
    $file=str_replace($invalidChars,"",$file);
    if( file_exists($file) ) return true;
    return false;
    }
    function compress($buffer) {
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
    return $buffer;
    }
    ?>
    I then added this to my .htaccess file:

    RewriteEngine on
    RewriteRule ^(.*).js$ pathtoyourwebsite/gzip.php?file=$1.js [L]
    Now all my scripts are compressed. I still have not figured out how to combine the external scripts, but I am pleased with them all being compressed. Saves a lot of space. Hope this is helpful! Moreslides

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.