Skip to content

Latest commit

 

History

History
120 lines (81 loc) · 8.24 KB

help.textile

File metadata and controls

120 lines (81 loc) · 8.24 KB

Speed up your TXP websites! 🚀 (Plugin Prefs)

Initially inspired by strategies used by Google and Yahoo!, the pat_speeder plugin for Textpattern CMS compresses your pages into a single line of code before sending them to browsers.

The process is immediate. By removing tabs, line breaks, comments and unnecessary spaces (which are all absolutely not necessary for your site to display properly), your pages are accelerated. Speed ​​increases by up to 10-20%! Generally (observed results), Google Page Speed Insights scores are better (100/100, or close to it)!

pat_speeder is non-intrusive: your templates and CSS style sheets are not affected. You maintain your organization. Your code remains readable, as you designed it, and only for you. The effectiveness of pat_speeder benefits your visitors’ experience.

Simple and easy to use, a single tag to instantly boost your websites.

This plugin’s settings depend on two independent options:

  • By the options available in “the plugin’s preferences panel”:?event=plugin&step=plugin_help&name=pat_speeder#plugin_help_section_plugin_preferences_panel (with precedence based on tag attributes on demand);
  • By its “tag attributes”:?event=plugin&step=plugin_help&name=pat_speeder#plugin_help_section_attributes.

Remember: regardless of your choices, you must specify the mandatory <txp:pat_speeder /> tag into all your pages.

Warning: This plugin seems not to be compatible with some Flash audio players (to be confirmed; however, Flash is no more used).

Additionally, to preserve the spaces before and after each link (“a” tags), spaces are kept between each HTML code to preserve the visual appearance. However, these extra spaces are not part of natural and well-written text content. Keep this in mind: write quality content and optimize compression (in particular, spaces between <a> tags will be removed). In this context, an additional preference is available for “Compact Compression”, which removes all spaces (default: “false”). In this case, it is recommended to manually add them before and after (&nbsp;).

Test results

According to Ruud’s Benchmarks (emeritus Core Dev), this plugin results in a reduction of 5% (for pre-compressed pages) to 6% (for normal pages). Or even more according to the GTmetrix performance tool. In addition, it allows for better “Google Page Insights” scores (100/100 or close to). ✌️

Plugin Preferences panel

After installation, go to your website preferences:

  • Enable pat_speeder? Allows you to enable/stop rendering of this plugin on all your pages where its tag is used (not in case the enable attribute is set to 1);
  • Enable GZIP compression with pat_speeder? Choose to activate the internal GZIP compression if needed (you may set your .htaccess file instead) only if the gzip attribute isn’t set into this plugin tag;
  • List of tags to protect from pat_speeder A comma separated list of tags to protect against the plugin throughout all the site. Default: script, svg, pre, code. Note: textarea is included into the plugin;
  • Enable extreme compression? This is a “compact mode” that removes all unnecessary spaces (to be precise: 2 or more) between all tags to return a smaller document in size. Bear in mind that your page and form markup must be cleanly written without additional spaces/tabs around tags. This can otherwise render in unexpected results such as text content directly adjacent to one another (e.g. a link running straight into text). As such, this setting is recommended only for advanced users.
  • Keep all HTML/CSS/IE/Google comments? Set to Yes, this setting keeps all these elements (if you choose No, Google comments will be removed but not its wrapped content).

Note: All preferences of this plugin can be overridden by the corresponding plugin attributes.

Usage

Add the following tag at the very top of your page templates:

<txp:pat_speeder />

Without any attributes, the plugin preferences take precedence.

Attributes

This plugin has the following attributes:

  • enable (boolean): set to 1 activate the plugin. Set to 0 disabled it. Default 1 (yes).
    (this attribute overwrite the corresponding plugin’s preferences : usefull if you want select some pages unchanged)
  • gzip (boolean) (optional): server side gzip compression. Default: 1 (true).
    (this attribute overwrite the corresponding plugin’s preferences)
  • code (string) (optional): a comma separated list of tags name on which do not apply compression. Default: script,svg,pre,code
    (this attribute overwrite the corresponding plugin’s preferences)
  • compact (boolean) (optional): further reduction by removing all duplicate spaces. See note in documentation).
    (this attribute overwrite the corresponding plugin’s preferences

Note: All these attributes override the corresponding preferences of this plugin on demand depending on individual pages.

Advice: You may not need to keep your JavaScript unchanged: it is recommended to take advantage of specific compression tools to use optimized code in production.

Example

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

In this case, pat_speeder isn’t enabled into the current page template (even if the corresponding preference is set to Yes).

Note: This tag should be placed at the very top of your pages.

Changelog

  • v0.1 on Jul, 22sd 2009. First release
  • v0.2 on Jul, 26th 2009. Second release. Adding some code submitted by Rudd.
  • v0.3 on Jul, 28th 2009. Third release. Mask html comments and css comments but preserve IE conditional comments.
  • v0.3.a on Jul 2009. Intermediate pre final release. The array() had been changed by a stronger regex.
  • v0.3.b on Jul, 30 2009. Final release. Support for pre tags.
  • v0.4 on Jul, 29th 2009. Non intrusive release: Add “enable” attribute.
  • v0.4a & v0.4b. Unpublished. For testing purposes only.
  • v0.4c on Jul, 06 2011. Add support in regex for “HTML5/Boilerplate” doctype declaration method.
  • v0.4.d on August, 18th 2013. Minor changes for better support of pre & code statements.
  • v0.5 on March, 25th 2014. Corrects removing space between some tags.
  • v0.6 on March, 27th 2014. Corrects errors. Remove HTML comments.
  • v0.7 on May, 26th 2015. Add server side compression. Add “gzip” attribute. Better new line removing server system independant.
  • v0.7.1 on May, 30th 2015. Remove extra spaces between all tags.
  • v0.7.5 on June, 22th 2018. Improvement; keep google bot comments.
  • v1.0 on July, 14th 2018. better support for IE conditional comments into the head part of the document; support for the Google comments (i.e. <!--googleoff: all-->); better support for accentuated languages.
  • v1.1 on July, 23th 2018. Final version.
  • v1.1.1 on August, 25th 2018. Add option to only compress when the site production status is ‘live’.
  • v1.1.2 on November, 18th 2019. Correct tag registration.
  • v2.0 on March, 1st 2024. Global revision of the code.
  • v2.3 on January 5th 2025. Remove HTML and CSS comments but keep Google ones.
  • v2.4 on March 5th 2025. Improve removing comments and preeminence of the plugin tag on preferences settings.
  • v2.5 on April 19th 2025. Overall Improvements.
  • v2.6 on November 16th 2025. Some corrections (Thanks Philippe).

See also the forum thread for requests or help.

Additional Optimization

Not needed for version 0.7: information retained for posterity.

If you want to further reduce the size of your website and assets, you can take advantage on your server’s gzip compression for all your other files (css, javascript, php, images) regardless of where they are located. This can produce significant gains of up to 80%. In your .htaccess file, add the following 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.*
</IfModule>

Acknowledgments

Special thanks to Ruud for his good advice and to Jakob for some code reviews (previous version).