Пример #1
0
 /// <summary>
 /// Strips the whitespace from any .js file.
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 protected override string Minify(StreamReader reader)
 {
     if (Settings.Instance.MinifyContent)
     {
         JavaScriptMinifier _Minifier = new JavaScriptMinifier();
         return _Minifier.Minify(reader);
     }
     else
     {
         return base.Minify(reader);
     }
 }
Пример #2
0
    /// <summary>
    /// Retrieves the local script from the disk
    /// </summary>
    private static string RetrieveLocalScript(string file, List <string> localFiles)
    {
        if (!file.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
        {
            throw new System.Security.SecurityException("No access");
        }

        string path   = HttpContext.Current.Server.MapPath(file);
        string script = null;

        if (File.Exists(path))
        {
            using (StreamReader reader = new StreamReader(path))
            {
                Miron.Web.MbCompression.JavaScriptMinifier jsMinifier = new Miron.Web.MbCompression.JavaScriptMinifier();
                script = jsMinifier.Minify(reader);
                //script = reader.ReadToEnd();
            }

            localFiles.Add(path);
        }

        return(script);
    }
Пример #3
0
 /// <summary>
 /// Process & Write a StreamReader to an output stream
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="context"></param>
 /// <param name="encodingMgr"></param>
 private static void ProcessAndWriteToStream(StreamReader reader, HttpContext context, EncodingManager encodingMgr)
 {
     string content = SR.GetString(SR.CREDIT_STRING);
     if (Settings.Instance.MinifyContent)
     {
         if (context.Response.ContentType.Contains("javascript"))
         {
             JavaScriptMinifier _Minifier = new JavaScriptMinifier();
             content += _Minifier.Minify(reader);
         }
         else if (context.Response.ContentType.Contains("css"))
         {
             CssMinifier _Minifier = new CssMinifier();
             content += _Minifier.Minify(reader);
         }
         else
         {
             content += reader.ReadToEnd();
         }
     }
     else
     {
         content += reader.ReadToEnd();
     }
     if (encodingMgr.IsEncodingEnabled && Settings.Instance.CompressWebResource)
     {
         encodingMgr.SetResponseEncodingType();
         byte[] compressed = encodingMgr.CompressString(content);
         context.Response.OutputStream.Write(compressed, 0, compressed.Length);
     }
     else
     {
         context.Response.Write(content);
     }
 }