Creating faster web pages

More
12 years 6 months ago #617 by magne
So here's my first tip: use one single stylesheet and javascript file instead of many small ones. I know one big file is harder to maintain, but once your site goes into production, you shouldn't have to change these files often anyway. Some sites like slashdot.org or fb01448c5ad7245925a07d05f1b0fab5-gdprlock reference dozens of .css and .js from their front page. Slashdot takes about twenty seconds for me to load from a clear browser cache. Don't go this mad with your css unless you have enough regular readers already. For someone new to your site coming over from Google this will be a major turn off.

If your stylesheets are static files and you would like to keep them seperate for better maintenance, you can bundle them into one request dynamically:

<?php
# File css.php
readfile("stylesheet1.css");
readfile("stylesheet2.css");
?>
As Kevin Palms points out, you will have to set the header information manually in PHP like this:

# File css.php
header('Content-type: text/css');
# ...
Save this code as a file called something like css.php and reference it from your HTML:

<link rel="stylesheet" type="text/css" href="/css.php" />

Please Logg inn or Create an account to join the conversation.

Time to create page: 0.262 seconds
Powered by Kunena Forum