Javascript – Supplying non-minified CSS/javascript on demand

cssjavascriptminifyrest

Minfying your stylesheets and script files improves your site's performance.

However, sometimes you might want to make the non-minified versions of the files available – perhaps to comply with the GPL or to implement the optional code-on-demand REST constraint.

Is there a standardised way of doing this? The only way I can think of is to use a naming convention:

http://example.com/css/styles.min.css – minified version

http://example.com/css/styles.css – non-minified version

The trouble with this approach is that it relies on an out-of-band convention. Is there any more rigorous way of implementing non-minified code-on-demand?

Best Solution

You could have some form of handler (e.g. a .NET handler) for .css files that serves up the minified version by default, but if a certain parameter was found in the querystring (e.g. debug=true) then serve up the non-minified version.

That way you can always reference the .css version, and if there is a minified version available, that can be used in preference.