Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Plugin support
  3. » pat_speeder

#1 2009-07-23 19:14:22

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

pat_speeder

Did you ever seen the source of Google’s html page? For speed reasons, Google is serving all 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 will be served into one line of code.

Note. It’s my very first plugin. A very simple one. Be Nice. Comments are welcome.

Versions History:

pat_speeder_v0.1 Very simple beta realize (22 Jul 2009).
pat_speeder_v0.2 Add some suggestions from Ruud (24 Jul 2009).
pat_speeder_v0.3 Mask your html/css comments but preserve specific IE conditional comments (28 Jul 2009).
pat_speeder_v0.3.a The array had been changed by a stronger regex. Spaces between html elements and characters content are now preserved (i.e. <img src="... /> <a href=""...). This version is the pre final one. It’s strongly recommanded to use it. Tks. (28 Jul 2009).

Final realize: pat_speeder_v0.3.b Add support for <pre> tags (30 Jul 2009). Finaly your better choice

Special “Non-Intrusive Realize”: *pat_speeder_v0.4*: Need to be added at the very top of each page templates (<txp:pat_speeder enable="boolean" />). Support on demand boolean 1 or 0 into “enable” attribute to choose which page to process. No compressing for CSS database files (29 Jul 2009). If you need to compress your CSS files, tell me: I have a solution.

Latest: version 0.4.c support for “HTML5/Boilerplate” doctype declaration method added into regex (06 Jul 2011).

The promotional website

Have fun.

Last edited by Pat64 (2015-05-06 13:52:05)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2009-07-26 09:16:41

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: pat_speeder

Thanks Pat64.

Offline

#3 2009-07-26 09:40:26

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: pat_speeder

Now that’s a small plugin!

How much bandwidth does this save if the website serves the pages using compression?

People who use pre-formatted text on their website shouldn’t use this plugin.

Offline

#4 2009-07-26 09:52:06

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: pat_speeder

ruud wrote:

People who use pre-formatted text on their website shouldn’t use this plugin.

Hi Rudd, what do you mean by pre-formatted text and why should it be used?

Thanks
Lee

Offline

#5 2009-07-26 09:59:39

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: pat_speeder

lee wrote:

what do you mean by pre-formatted text and why should it be used?

Hi Lee,

I guess (please someone do correct me if i am wrong or if i missed something) what ruud says is for people who use tags like bc. or the html <pre> or <code> tags should not use this plugin.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2009-07-26 11:07:49

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: pat_speeder

^^ yes, that’s what I meant.

Offline

#7 2009-07-26 12:33:59

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: pat_speeder

ruud wrote:

Now that’s a small plugin!

First. Sure! It’s my first one. I need to start with something :)) And now I’ll could go working on a bigger one…

Second. Thx for your warning.

On your recommendation – in the purpose to see what’s will occured – I’d try to add this into an article ( “Welcome to your site” on a fresh TXP 4.2.0 install):

bc. Test
 <pre><code>Test </code></pre> (starting line with a space for no textile rendition)

I’ve got this (as expected) within my source when this plugin is activated:

<pre><code>test </code></pre> <pre><code>Test </code></pre>

Could you tell me what’s the problem.

Best regards,

Last edited by Pat64 (2009-07-26 12:44:54)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#8 2009-07-26 12:54:09

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: pat_speeder

Check how it looks in the browser, not in the HTML code. The plugin shouldn’t affect how it looks for the visitor of the website.

Before:

<pre>three
separate
lines</pre>

After (well, not exactly, but you get the idea):

<pre>one long line</pre>

PS. the ‘small plugin’ comment was a compliment. I like small plugins.

Offline

#9 2009-07-26 13:45:36

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: pat_speeder

Patrick

Great to see you publishing your first plugin — congratulations!

Ruud wrote:

How much bandwidth does this save if the website serves the pages using compression?

Just like Ruud, I’d love to see some stats on the speedup this one gives. Are there any stats available for bandwidth reduction and/or time taken to process HTTP requests?


Steve

Offline

#10 2009-07-26 14:32:16

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: pat_speeder

ruud wrote:

Check how it looks in the browser, not in the HTML code. The plugin shouldn’t affect how it looks for the visitor of the website.

Before:

<pre>three
separate
lines</pre>

After (well, not exactly, but you get the idea):

<pre>one long line</pre>

-> Oh Yes I see now. You’re right Ruud (as always ;)

Thx lot.

net-carver wrote

Just like Ruud, I’d love to see some stats on the speedup this one gives. Are there any stats available for bandwidth reduction and/or time taken to process HTTP requests?

No stats. I’d just “see” (shame on me) a better page rendition for the 4 live websites I tested (even on one with a compressor.php script for javascript and css files)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#11 2009-07-26 17:50:13

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: pat_speeder

You can partially solve the PRE thing, by doing this (doesn’t catch CSS-based pre formatted styles):

function pat_speeder($buffer)
{
	if (FALSE === strpos($buffer, '<pre'))
	{
		$buffer = preg_replace('/\s+/', ' ', $buffer);
	}
	return $buffer;
}

Offline

#12 2009-07-26 18:12:51

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: pat_speeder

I did some testing:

Without compression:
before: 22794
after: 22,314 (2.1% reduction due to plugin)

With compression:
before: 7989 [compressing gives a 65% reduction!]
after: 7842 (1.8% reduction due to plugin)

Not sure if this breaks anything. It assumes that whitespace surrounding tags is pointless.

$buffer = preg_replace('/\s+/', ' ', $buffer);
$buffer = str_replace(array(' <', '> '), array('<', '>'), $buffer);

normal: 21955 (3.7% reduction)
compressed: 7789 (2.5% reduction)

Add comment removal (which was commented out, probably because it doesn’t properly handle all valid comments, but it works for simple comments):

$buffer = preg_replace('/\s+/', ' ', $buffer);
$buffer = str_replace(array(' <', '> '), array('<', '>'), $buffer);
$buffer = preg_replace('/<!--.*?-->/', '', $buffer);

normal: 21415 (6.0% reduction)
compressed: 7563 (5.3% reduction)

Offline

  1. Index
  2. » Plugin support
  3. » pat_speeder

Board footer

Powered by FluxBB