Skip to content
OnkelHenky edited this page Feb 18, 2011 · 4 revisions

Task ContenType

This task is for check the file extension of the files of framework and attache the correct content-type to each file. The content.typ is used by the m-server process to deliver the file correctly.

Each File object contains function to check the file extension e.g.: '.js','.css','.json' or '.png'. The core of this task is to switch through the file extension of the file of a framework and map this to a concret content-type

Task_ContentType.prototype.duty = function(framework,callback){
var self = this;

 this.contentTypes = {
    ".js"      :  "text/javascript; charset=utf-8",
    ".css"     :  "text/css; charset=utf-8",
    ".manifest":  "text/cache-manifest",
    ".html"    :  "text/html",
    ".png"     :  "image/png",
    ".jpg"     :  "image/jpeg",
    ".gif"     :  "image/gif",
    ".svg"     :  "image/svg+xml",
    ".json"    :  "application/json"
  };
    
  framework.files.forEach(function(cF){
    cF.contentType = (contentTypes[cF.getFileExtension()]) ?contentTypes[cF.getFileExtension()] :  'text/plain';  
  }  
  callback(framework);
};
Clone this wiki locally