Skip to content

Commit

Permalink
forced UTF-8 charset for text assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Aug 10, 2012
1 parent 0b0535a commit 234041a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/mincer/server.js
Expand Up @@ -113,6 +113,17 @@ function is_compressable(asset) {
}


// Returns whenever an asset is text or not
var TEXT_MIME_RE = new RegExp([
'^text/',
'/json$',
'/javascript$'
].join('|'));
function is_text(asset) {
return TEXT_MIME_RE.test(asset.contentType);
}


// Tells whenever browser accepts gzip at all
function is_gzip_accepted(req) {
var accept = req.headers['accept-encoding'] || '';
Expand Down Expand Up @@ -381,9 +392,9 @@ Server.prototype.handle = function handle(req, res) {

//
// Set content type and length headers
// Force charset for text assets, to avoid problems with JS loaders
//

res.setHeader('Content-Type', asset.contentType);
res.setHeader('Content-Type', asset.contentType + (is_text(asset) ? '; charset=UTF-8' : ''));
res.setHeader('Content-Length', length || asset.length);

res.statusCode = 200;
Expand Down

0 comments on commit 234041a

Please sign in to comment.