Speed up your TXP websites now!

Did you ever seen the source code of the Google main html page? For speed reasons, Google serves its home page into one line of code. The benefit is a server bandwidth gain. So what don't we make the same for ours TXP websites?

Just activate this plugin and your page templates and database css files (not in this version) will be rendered into one line of code.

Warning: This plugin seems not to be compatible with some flash audio players (to be confirmed).
Important: if comments are present into inline javascript code (i.e. // Comment here) they will be put into the firts line of javascript code causing defects. Solution: use these form of comments instead (/*! code here */):

/*! Simple CSS loader asynchronously for all browsers by cara-tm.com, MIT License */
var e,m;function LoadCSS(e,m){"use strict";var r=document.createElement("link");if(m?"":m="all",r.rel="stylesheet",r.href=e,r.media=m,"undefined"!=typeof r){var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(r,s);}}
/*! Load files */
LoadCSS("../css/advanced.min.css", "only screen");
LoadCSS("../css/print.min.css", "print");

Test results #

This plugin gives a benefit rendition between 5% (for precompressed pages) and 10% (normal pages) according to Ruud's observations.

Included automatic server side GZIP compression, if available, gives an average additional benefit of 75%. This plugin (v 0.7) seems to get better results than ask_header (v 0.3.6) up to 0.7% (based on a vanilla default TXP installation tested on http://checkgzipcompression.com/).

Usage #

At the very top of your page templates add this tag:

<txp:pat_speeder />

Attributes #

This plugin accepts only three attributes:

enable boolean: set to 1 activate the plugin. Set to 0 disabled it. Default 1 (yes).

gzip boolean: set to 1 enable gzip server compression (if available). Default: 1 (yes).

code string (optional): a comma separated list of tags name on which do not apply compression. Default: script,code,pre

Example #

<txp:pat_speeder enable="0" /><!DOCTYPE ...

In this case, pat_speeder is'nt enable into this current page template.

Changelog #

First realize: v0.1 on 22 Jul 2009
Second realize: v0.2 on 26 Jul 2009. Adding some code submitted by Rudd.
Third realize: v0.3 on 28 Jul 2009. Mask html comments and css comments but preserve IE conditional comments.
Intermediate pre final realize: v0.3.a on Jul 2009. The array() had been changed by a stronger regex.
Final realize: v0.3.b on 30 Jul 2009. Support for <pre> tags.
Non intrusive realize: v0.4 on 29 Jul 2009. Add "enable" attribute.
Confidential Versions : v0.4a & v0.4b for tests only.
Boilerplate/HTML5 capable: v0.4c on 06 Jul 2011. Add support in regex for "HTML5/Boilerplate" doctype declaration method.
v0.4.d on 18th August 2013. Minor changes for better support of pre & code statements.
v0.5 on 25th March 2014. Corrects removing space between some tags.
v0.6 on 27th March 2014. Corrects errors. Remove HTML comments.
v0.7 on 26th May 2015. Add server side compression. Add "gzip" attribute. Better new line removing server system independant.

See also the Forum Thread for requests or help

Additional Optimization Advices #

Never need with version 0.7: keep it here for information.

If you want to add more speed on your websites, you can take advantage on your server's gzip compression for all your other files (css, javascript, php, images) - never mind where they are located - with signifiant gains up to 80%.
In your .htaccess file, just add this lines of code:

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

Acknowledgments #


Special thanks to Ruud for his good advices.