public void Reload() { this.bytes = File.ReadAllBytes(path); bool shouldCompress; this.contentType = MimeUtils.GetContentType(path, out shouldCompress, out isDownload); if (!path.Contains(".min.")) { var ext = Path.GetExtension(path); switch (ext) { case ".css": { var temp = Encoding.UTF8.GetString(bytes); temp = CSSMinifier.Compress(temp); this.bytes = Encoding.UTF8.GetBytes(temp); break; } case ".js": { var temp = Encoding.UTF8.GetString(bytes); temp = JSMinifier.Compress(temp); this.bytes = Encoding.UTF8.GetBytes(temp); break; } case ".html": { var temp = Encoding.UTF8.GetString(bytes); temp = HTMLMinifier.Compress(temp); this.bytes = Encoding.UTF8.GetBytes(temp); break; } } } if (shouldCompress && (this.bytes.Length < 1400 || this.bytes.Length > 1024 * 512)) { shouldCompress = false; } this.isCompressed = shouldCompress; this.hash = StringUtils.MD5(this.bytes); if (shouldCompress) { this.bytes = this.bytes.GZIPCompress(); } }
public Document FindTemplate(string name) { lock (_cache) { DateTime lastMod; var fileName = filePath + name + ".html"; if (!File.Exists(fileName)) { if (_cache.ContainsKey(name)) { return(_cache[name].document); } return(this.On404(name)); } lastMod = File.GetLastWriteTime(fileName); if (_cache.ContainsKey(name)) { var entry = _cache[name]; if (lastMod == entry.lastModified) { return(entry.document); } } string content; content = File.ReadAllText(fileName); if (Server.Settings.Environment == ServerEnvironment.Prod) { content = HTMLMinifier.Compress(content); } var doc = Compiler.CompileTemplate(content); _cache[name] = new CacheEntry() { document = doc, lastModified = lastMod }; return(doc); } }