|
[Web Development Tut] Compress your CSS with PHP
|
|
06-02-2010, 06:28 PM
(This post was last modified: 06-02-2010 06:30 PM by euantor.)
Post: #1
|
|||
|
|||
|
[Web Development Tut] Compress your CSS with PHP
When developing large sites, you can end up with giant CSS files with all your styles and everything in them. Why not compress the blighters and save yourself space, bandwidth and loading time? Now, you may be thinking "well, just remove whitespace, use shorthand, try not to write the same entry multiple times..." However, these methods can only help so much, yet you can still compress more.
It's very simple to do using just PHP - take a look below! Step 1 First of all, let's start a new PHP file. So, make a file like gzip-css.php. Within this file, add this following code at the top; Code: <?phpLet's take a look at what this code actually does...
Step 2 Ok, so now let's create our stylesheet. We'll call it style.css and save it in the same directory as gzip-css.php Code: body {Step 3 Great, so that's our .php and .css files sorted (or our stylesheet). Now, let's actually make them interact. We do this using a .htaccess file. Add the contents below to a new .htaccess file and save it to the same directory as the gzip-css.php and style.css files. Code: AddHandler application/x-httpd-php .cssThis .htaccess rule does 3 things;
Step 4 And now to actually include the stylesheet in your HTML document. You just do this using the usual method; Code: <link href="style.css" rel="stylesheet" type="text/css" />There we go. All done! Easy eh? If you want, you can even download the files I made during this tutorial below and take a look yourself! |
|||
|
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)




