PaulHanak
PaulHanak

Reputation: 739

can you not compress CSS but work on it later?

I've even looked at CSS Crush, Minify, SmartOptimizer, CSSTidy and a slew of other PHP CSS compressors. But they all have one major flaw.

You can't use this:

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

When using dreamweaver, this is the only way to see the DESIGN in DESIGN VIEW. If you replace that styles.css file with styles.php, it breaks, even if you HAVE css code in the file..

I am using minify for my JS and it is working beautifully, but if I use it with CSS, Dreamweaver gets scared and doesn't know how to render it. haha. Of course, it IS server side though.

Does anybody have a workaround for a situation like this? I do prefer to use dreamweaver because of the immediate changes that can be made in design view, as well as the FTP capabilities and code hinting, but even the new CS6 seems to whine when you use anything BUT a .css file.

Upvotes: 2

Views: 291

Answers (2)

Kyle Lacy
Kyle Lacy

Reputation: 2278

I can't verify that this solution will work, but it should theoretically.

First, you'll want to add .css files as PHP, so you don't have to change the file extension. This is good practice regardless, since the file extension should indicate what content is being delivered. I don't know that there's any standard that states this outright, but it's good practice. If you're using Apache, you can add this to your .htaccess or global server configuration file:

AddHandler php5-script .css

Then, just <link rel="stylesheet" href="css/style.css" type="text/css" /> after renaming your file back to CSS. For more details on this, see the Apache docs on AddHandler.

Second, you'll want to 'comment out' your PHP code within your CSS. For example, you could do something like this at the top of style.css:

/*
    <?php include 'your-file-compressor.php'
    // Put any PHP code for compression here
    ?>
*/

That way, Dreamweaver will still read the actual CSS code, but PHP should be able to compress before delivering it to clients.

Upvotes: 2

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57690

As Kishore pointed out, Minificaiton should be part of build process. While development you should use the raw css file.

Instead of href="css/styles.php" its better to use href="compresscss/path/css/styles.css". Here compresscss/path/css/styles.css is mapped to compresscss.php?path=css/style.css. This can be done by mod_rewrite in apache.

This way dreamweaver will see it as an css file and also you will compress it.

Upvotes: 1

Related Questions