css minification

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 17 18:21:29 PST 2015


On Sunday, 18 January 2015 at 02:11:13 UTC, Andrei Alexandrescu 
wrote:
> Who's "you"? :o) -- Andrei

I'd do it myself, but after spending 30 minutes tonight trying 
and failing to get the website to build on my computer again 
tonight, I'm out of time.

It really isn't hard though with access to the html and .htaccess 
or something.

I just slapped this on my this-week-in-d local thingy:

.htaccess:

RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]

<FilesMatch \.css\.gz$>
     ForceType text/css
     Header set Content-Encoding gzip
</FilesMatch>

<FilesMatch \.js\.gz$>
     ForceType text/javascript
     Header set Content-Encoding gzip
</FilesMatch>

<FilesMatch \.rss\.gz$>
     ForceType application/rss+xml
     Header set Content-Encoding gzip
</FilesMatch>

ExpiresActive on
ExpiresDefault "access plus 1 days"




Then ran

$ for i in *.html *.css *.rss *.js; do gzip "$i"; zcat "$i.gz" > 
"$i"; done;


(gzip replaces the original file so i just uncompressed it again 
after zipping with zcat. idk if there's a better way, the man 
page didn't give a quick answer so i just did it his way)


and the headers look good now. So like if that can be done on 
dlang.org too it should hopefully do the trick.


More information about the Digitalmars-d mailing list