• Jan
  • 23

Site speed boost script updated

Version 0.4 is now available. It now features:

  • An installer.Lots of people were having problems with the paths, so we now have an installer that*should* take care of everything very easily. If you need to change anything you can either just re-run the installer, or change the config.php file directly.
  • Full support for relative image paths in your CSS, in multiple CSS files. Image paths in CSS are now converted to absolute paths, so you no longer have to worry about where to cache the CSS.
  • Added support for different rel types. (rel=”alternative” and rel=”stylesheet” are cached separately)
  • Added support for conditional comments in the HEAD tags (this also fixed the problem of commented out stylesheets)

It’s available from this page: PHP Speedy

———————————–

Version 0.3 is now available.

  • Added check for gzip compression compatibilty.
  • Added check for external javascript files
  • Fixed bug in head grab function

It’s available for download here: aciddrop website speedup v0.3

You can see the new demo online here:

Many thanks to those who contributed with bugs and fixes.

———————————–

Version 0.2 Info

Following feedback on the compression class (thanks to all who commented), version 0.2 is now available.

Changes include:

  • Added support for different CSS media types
  • Fixed bug in relative file paths.
  • Improved file cleanup function
  • Changed file versioning to by date instead of by file size
  • Added check for trailing slash on cachedir

You can see the new demo online here:

In testing this new version I found a couple of gotchas:

  • Don’t use it at the same time as my Smarty output class that joins the CSS and Javascript. Apache will get confused.
  • Don’t comment out any stylesheets in your HTML if they’re not in use. The class can’t recognise that (yet!).

Also, for those wondering if it works with Wordpress, I changed the code of this Wordpress theme to use the new class.


Related posts

Posted by admin in php, tutorials
trackback
 

  • Jan
  • 23
jimbo
jimbo

I am trying to find a valid way to test this script.
I take a huge text file of 1meg.
I use php to open it and echo it to the screen.
$file=fopen(”mess”,”r”) or exit(”Unable to open file!”);
while (!feof($file))
{
echo fgetc($file);
}
fclose($file);

then i add the script.
Everything is fine except i add to add more memory to php (which is fine with me)

The only thing is that according to yslow it doesnt improve the performance at all. It add to it.

Any suggestion on how i should try it “the right way” to impress my boss.

Thx.

  • Jan
  • 23
admin
Leon

jimbo - this script is most effective when you have lots of javascript and CSS files. Looks at the source of the demo http://aciddrop.com/aciddrop/minify-0.2/compress_me.php?compress=no without compression. You’ll see several JS and CSS files.

Now look at the source of the demo with compression: http://aciddrop.com/aciddrop/minify-0.2/compress_me.php

All the relevant JS and CSS files have been combined, and they have been gzipped.

So to best impress your boss show him a page with lots of JS and CSS before and after compression.

  • Jan
  • 23
Alan Bollinger

OK seriously kick ass. Reduced my pages from 30k to 8! Great job.

  • Jan
  • 23
Bret
Bret

Lots of PHP Notices in there:

Notice: Undefined index: cachedir in c:\…\class.compressor.php on line 102
Notice: Undefined variable: return_array in c:\…\class.compressor.php on line 491
Notice: Use of undefined constant ext - assumed ‘ext’ in c:\…\class.compressor.php on line 412

Notice: Undefined index: rel in c:\…\class.compressor.php on line 414

Notice: Undefined index: media in c:\…\class.compressor.php on line 418

And don’t tell me to turn notices off ;-)

PS: Still using 0.2 since the 0.3 seems to be broken.

  • Jan
  • 23
admin
Leon

Notices eh? I must confess to working with them turned off. I’ll look into fixing them.

How does 0.3 break for you?

  • Jan
  • 23
Bret
Bret

The windows ZIP extractor reports the ZIP file to be corrupt.

  • Jan
  • 23
admin
Leon

Strange, it opens OK here for me. I’ve uploaded it again just in case. Could you perhaps be running low on memory in windows? Sometimes ZIP breaks for me when that happens.

  • Jan
  • 23
Bret
Bret

The ZIP issue seems to be one of Windows specialties.
Using another ZIP tool got me the same file opened :-(

  • Jan
  • 23
admin
Leon

Ah, OK, great.

  • Jan
  • 24
Lorenzo
Lorenzo

Hi Leon, I’ve some porblem opening the zip file on MacOsx 10.4 using both Suffit and BOMAArchiveHelper

I’ve the same problem opening it using unzip command in command line.

Any idea?

Thanks

  • Jan
  • 24
Justin

here’s why some zip apps can’t open it — it’s a RAR file.

  • Jan
  • 24
Fernando
Fernando

Use another program to unpack it will work! Ex: WinRar

  • Jan
  • 24
admin
Leon

Ooops, I compressed it as a RAR file and saved it as a ZIP. Apologies. It’s now a bona fide zip.

  • Jan
  • 24
Lorenzo
Lorenzo

Thanks… it’s ok now.

  • Jan
  • 24
horaciod

between lines 199 and 203 (version 0.3 )
if($head) {
preg_match_all(”!]+media=[\"'\s](.*?)[\"'\s][^>]+>!is”, $head, $matches);
}

//Run through the media types and sub in markers
if(is_array($matches) ) {

what happend if $head is false ?
corrected code

if($head) {
preg_match_all(”!]+media=[\"'\s](.*?)[\"'\s][^>]+>!is”, $head, $matches);
}else $matches=false ;

//Run through the media types and sub in markers
if(is_array($matches) and count($matches)>0) {

  • Jan
  • 25
TooCoolForYou
TooCoolForYou

Umm i dont know whats wrong, but i've using teh version 0.1 and it works fine, now im trying to use the 0.2 and 0.3 but i got errors.

This are teh initials params that i've using.

PHP:
var $compress_params = array("javascript"=>array("cachedir"=>"/cistronix/sigeco-web/cache","gzip"=>true,
    "minify"=>true),"css"=>array("cachedir"=>"/cistronix/sigeco-web/cache","gzip"=>true,"minify"=>true),"page"=>array("gzip"=>true,
"minify"=>true));

In the 0.2 version:

* Errors like.

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\cistronix\sigeco-web\libs\compressor.php on line 137

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\cistronix\sigeco-web\libs\compressor.php on line 641

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\cistronix\sigeco-web\libs\compressor.php on line 645

In the 0.3 version i just got a empty css and js file cache -.-

I know that this is not very helpful but whatever.

  • Jan
  • 25
admin
Leon

TooCoolForYou - the foreach() errors indicate that it can't find the option params. I have updated the ZIP file to include a new directory called test_page. Run the "compress_me.php" file in that directory and see if that works for you. Then take things from there. The new file is here:
http://aciddrop.com/aciddrop/minify-0.3/aciddrop_site_compression-0.3.1.zip

  • Jan
  • 25
mcalons
mcalons

fopen Permision denied
You said
"set the folder where you are running the class from as writable" ...

...But if I give writable permission could be a security problem, and if the folder is public_html in this case, :O! .. bigger security problem!

If this class need writable permision can give me problems ? How you solve this

  • Jan
  • 26
aNTRaX

Leon in next version you can combine the jsmin.php and the class.compressor.php? A lot of times I don't remember to copy the libs dir or change the include call and I get a error. And a script with only one file would be easier to implement.

Thanks

  • Jan
  • 26
admin
Leon

@mcalons: you change change the directory where the files are cached. Just start the class with the advanced options, and set the cachedir. For example:

PHP:
$compressor = new compressor(array("javascript"=>array("cachedir"=>'/wp-content',
"gzip"=>true,
"minify"=>true,
),
"css"=>array("cachedir"=>'/wp-content',
"gzip"=>true,
"minify"=>true,
),
"page"=>array("gzip"=>true,
"minify"=>true
)
));

@antrax: I'll consider it, although it's pretty standard practice to include libraries in the separate directory. What I will include perhaps is error checking, so that it will fail gracefully if the include isn't there.

  • Jan
  • 26
Horaciod

security implications
each pack of files (css and js) have a php header and then the code like this one

alert('hello');

what about a "bad guy javascript " like this

alert(' the password is ');

maybe is better just make an echo of the javascript like this

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

  • Jan
  • 27
matt
matt

Hey, it looks like a great script but I am not amazing at PHP and am having trouble implementing it.

What are the basic steps to get things going? I have the files unzipped and loaded into the root directory, all set to writable, and the sample code at the top and bottom of my pages code but it doesnt seem to change anything...

  • Jan
  • 28
Lars Olesen

May I suggest, that you make this great file available as a PEAR package. This is not to be confused with making it part of the PEAR project. All you have to do is create a PEAR package, and anyone will be able to install it like this:

pear install aciddrop/AcidDrop_Compressor

And when you make improvements to the code, just the following:

pear upgrade aciddrop/AcidDrop_Compressor

Let me know, if you are interested and need more help.

Also, what about making it available in an svn so other people can contribute, for instance code.google.com.....

  • Jan
  • 28
Quesir
Quesir

Hi! It's great tool! :)

But, is there a way to use it with Zend Framework?

  • Jan
  • 28
admin
Leon

Horaciod - the headers are added to the javascript that is taken from the script on your server, and that you have linked to in your . It's the same as your JavaScript file, but with headers added. I don't see how anyone could add JS code to it.

Matt - first see if you can get the script the in 'test_page' directory working ok. Extract everything from the ZIP into a few folder - let's call it test -, then set the 'test_page' directory to writeable. Then go to http://{yoursite}/test/test_page/. It should show a compressed page. Once you have that working, look at the 'compress_me.php' file in the test_page directory to see what it's doing, and go from there!

Quesir - I haven't used it with the Zend framework, but I don't see why not.

  • Jan
  • 28
admin
Leon

Lars - many thanks for the suggestions. Those are great ideas, I'll definitely consider put in them in place for the next release.

  • Jan
  • 28
Sachin
Sachin

Great tool, halved my site's load time BUT...
it seems to remove alternate stylesheets (i.e. link rel="alternate stylesheet") which breaks the style switcher I use on my site?

  • Jan
  • 28
matt
matt

Hey, thanks for the tip. Got it up and running now (speeds things up tremendously), but I got another issue for ya.

I had been playing around with dreamweaver cs3 for this site and had added what they call a 'spry collapsible panel' which is really just a menu type expandable tab built with html, css, and JS.

Well everything on the page worked great after the script except those panels, which no longer seem to have their JS functionality.

Any ideas?

  • Jan
  • 29
admin
Leon

Sachin - I hadn't taken alternte stylesheets into consideration, thanks for the heads up. I have added it to the to-do list. As a quick fix you can move them outside the <head> tags.

Matt - have a look at the source code of the page without the compressor activated. See if you can find where the Dreamweaver code is added. Now activate the compressor, and look again at the source code. What has changed with the Dreamweaver added code?

  • Jan
  • 29
phil
phil

Looks good but I have a few issues in getting it working.

I'm using Joomla v1.0.12 and adding this gives unexpected results. The page does not load and I just get a page or so of garbage....

I'd like to use this as I'm using more and more Javascript like Jquery and would really help to speed up load times.

Plus I'm using PHP v4.4.7 for the hosted site.

Any ideas on where to look at getting this working?

  • Jan
  • 29
matt
matt

Nothing changes in the code, I just double checked... what's also weird is once in awhile for the first second the page is loaded, the tabs seem to work, before breaking again almost immediately.

  • Jan
  • 29
Quessir
Quessir

@ Leon.

But I tried and output failed. It returns empty page (error_reporting turned on).

  • Jan
  • 30
admin
Leon

Phil - try turning the gzipping for the page off.

PHP:
"page"=>array("gzip"=>false,
"minify"=>true
)

matt - I had a look at the adobe demo page for the spry panel:
http://labs.adobe.com/technologies/spry/samples/...

It looks like it includes this JS and CSS:

CODE:
<script src="../../widgets/collapsiblepanel/SpryCollapsiblePanel.js" type="text/javascript"></script>  <link href="../../widgets/collapsiblepanel/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />

So it would seem the JS linked to there isn't being handled properly. First, try turning off JS minification. It could be the Dreamweaver code doesn't minify well. If that doesn't work, open up the compressed JS file created by the compressor (_cmp_javascript_etc), and look for the dreaweaver code. Is it there?

Quessir - try turning off page gzipping (as in my advice for Phil above).

  • Jan
  • 31
Justin

Does this script maintain style sheets loaded through conditional comments?

  • Feb
  • 1
admin
Leon

Justin - the latest version supports conditional comments in the HEAD tags.

  • Feb
  • 5
k\.
k\.

Hi,
Great script!
...but i can't get it working. I can't even run the install script, it just shows a blank page, which seems to come from a PHP error.
I tried to set the requires with the absolute path ($_SERVER['DOCUMENT_ROOT'] ... ...) but nothing changed. Blank page.
What should i check?

'hope i get a suggestion,
thanks. k\.

  • Feb
  • 28
admin
Leon

k - please try the latest version.

  • May
  • 8
Doufer

A wordpress plugins would be a very nice idea!

Congrats for the great job!

Comments are closed