Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
 public AssetCache(LoggerCallback logger, string filePath) : base(logger, filePath)
 {
     BuildAssetCache("js", "application/javascript", x => JSMinifier.Compress(x));
     BuildAssetCache("css", "text/css", x => CSSMinifier.Compress(x));
 }