Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • valic Friend
    #129998

    If you have large css files ( from templates, components, ….), you can compress this file very good with gzip ( a dont mean just enabling gzip in joomla configuration)

    Example:
    My site http://www.lijepanasa.info have template_css.css which it’s 30,3 kb.
    After it’s just 6kb for loading
    News portal css have around 160kb, and for loading just 10kb

    Here we go:
    1. create file template_css.php and in this file put this:

    <?php
    ob_start ("ob_gzhandler");
    header("Content-type: text/css;charset: UTF-8");
    header("Cache-Control: must-revalidate");
    $offset = 60 * 60 ;
    $ExpStr = "Expires: " .
    gmdate("D, d M Y H:i:s",
    time() + $offset) . " GMT";
    header($ExpStr);
    ?>
    <?php include ('template_css.css'); ?>

    Last line it’s your name of css files for template (<?php include (‘template_css.css’); ?>)

    2.Then you put this file (template_css.php) in directory where are included css file, in this case, css folder of your template.

    3. Open your index.php file of your template, and just replace line:

    <link rel="stylesheet" href="<?php echo $tmpTools->templateurl(); ?>/css/template_css.css" type="text/css" />
    with this:

    <link rel="stylesheet" href="<?php echo $tmpTools->templateurl(); ?>/css/template_css.php" type="text/css" />
    That works with any component, per example news portal:
    I have created file news_css.php:

    <?php
    ob_start ("ob_gzhandler");
    header("Content-type: text/css;charset: UTF-8");
    header("Cache-Control: must-revalidate");
    $offset = 60 * 60 ;
    $ExpStr = "Expires: " .
    gmdate("D, d M Y H:i:s",
    time() + $offset) . " GMT";
    header($ExpStr);
    ?>
    <?php include ('news.css'); ?>

    and i have put this file in /public_html/components/com_news_portal/

    and then i just in news_portal.html.php in line 661 instead this:

    @import url('.$mosConfig_live_site.'/components/com_news_portal/news.css);
    i put this:

    @import url('.$mosConfig_live_site.'/components/com_news_portal/news_css.php );
    Enyoy 🙂


    1. css_size
    kashxo Friend
    #255383

    Thank you valic,
    Very nice Tutorials. 🙂

    instantinlaw Friend
    #262554

    Another great tutorial valic.
    Thanks!

    tobefg Friend
    #490088

    Ok, but if i use joomla gzip should i alos use the template css and js compression?

Viewing 4 posts - 1 through 4 (of 4 total)

This topic contains 4 replies, has 4 voices, and was last updated by  tobefg 11 years, 6 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum