Posts

Showing posts with the label compress

Simple JavaScript/CSS gzipping

I'm sure some may already do this, but compressing textual content can save bandwidth but also make it easier to maintain (by just including a php file instead of a CSS or JavaScript one). For example, create a file jquery.php in the same directory as JavaScript files: <?php ob_start("ob_gzhandler"); header("Content-Type: text/javascript"); include("jquery-1.2.6.min.js") ?> Then include it instead of the normal JavaScript file: <script type="text/javascript" src="/js/jquery.php"></script> It's simple to maintain and could be improved (for example, some kind of caching). CSS files can also be used: <?php ob_start("ob_gzhandler"); header("Content-Type: text/css"); include("styles.css") ?>

CssCompact: A WebHandler for shrinking CSS files (ASP.NET)

Update (20 Feb 2010) : Static regular expression, compiled (performance improvement, but will be negligible for low volume sites). See Compacting CSS on-the-fly for an HttpHandler based on this. Update (08 July 2009) : Check file extension is CSS. CssCompact is a simple WebHandler for sending smaller CSS files to the client. It simply removes linebreaks, tabs, spaces (before CSS properties) and comments. That way you can still have your commented CSS code, and also save bandwidth. Use is simple, just pass on the stylesheet as a parameter when loading your stylesheet: Add to <head> : <link rel="stylesheet" type="text/css" href="/style/CssCompact.ashx?stylesheet=/style/style.css" /> or <style type="text/css"> @import "/style/CssCompact.ashx?stylesheet=/style/style.css"; </style> Create CssCompact.ashx : <%@ WebHandler Language="C#" Class="CssCompact" %> using System; using Syste...