Jump to content

Recommended Posts

This may not relate directly to PHP Coding (I'm not entirely sure), I really wasn't sure where to post it, so apologies if it's in the wrong area.

 

I recently came across the Yslow plugin for Firefox, and have been using it to check out the 'performance' of a site I've been working on. There are a few parts of this that I'm not familiar with and was hoping somebody could shine some light on the matter. Pretty much all the low scores I recieved were in the 'SERVER' tab, which makes perfect sense as they are mainly the features I'm not familiar with.

 

Use a Content Delivery Network (CDN)

I'm not sure about the details of this, I'm guessing (and hoping) that this is only really important for Large websites that may have a lot of multimedia on them? Any clarifcation would be great.

 

Add Expires headers

I'm assuming this is refering to sending a specific header for the files, which I know can be done using the header function. Like so...

 

<?php header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); ?>

 

But the Yslow plugin is telling me that the files it has a problem with are the css, gif and jpg files, so how do we solve the problem with this? Apache .htaccess files perhaps?

 

Compress components with gzip

Not a clue about this one, I have a feeling this is going to be an Apache issue.

 

Configure entity tags (ETags)

Again not a clue.

 

The further through this page I got the more I feel perhaps I should of posted under Apache or something? But I'm hoping the problems can be solved with PHP so I don't have to mess with too many Apache configuration settings (due to server restrictions).

Link to comment
https://forums.phpfreaks.com/topic/176060-optimising-performance-with-yslow/
Share on other sites

idk about the others, but the 'expires' header can be sent with a tiny run around :)

 

RewriteRule ^(.*\.css)$ css.php?file=$1

 

and in css.php

 

<?php

  header('Content-Type: text/css');

  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

  readfile($_GET['file']);

?>

?>

I realise I can use the header function to set the headers to the correct values, what I don't understand is how exactly to implement that. If I have a css.php with the code you gave in (ignoring the $_GET['file'], with the correct uri listed instead) how would I apply that to a standard HTML structured file?

 

As a simple example let's say I have...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/styles.css" media="screen, projection, tv " />
</head>
<body>
</body>
</html>

 

Am I understanding correctly that I would have the link href as href="/css/css.php" and then readfile(/css/styles.css) within that file?

 

Also how do I apply the same theory to the images, bearing in mind alot of them are only referenced in the css (I will be changing the multiple files to a css sprite as soon as I can be bothered to learn how).

no no you won't change any link tags or anything, just add the css.php file to your home directory, then in the .htaccess put:

 

RewriteEngine on

RewriteRule ^(.*\.css)$ css.php?file=$1

 

and htaccess will keep the usual url but will point to the css.php file pass the file via get and css.php will push headers from php then echo the file's contents :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.