压缩

问题描述:

的负载形式,我在写我的一个基于客户端的活动现场压缩

public ActionResult Javascript(string filename) 
{ 
    var fileLocation = Server.MapPath(string.Format("~/Views/SiteFiles/{0}/js/{1}", Profile.SiteSlug, filename)); 
    if (!System.IO.File.Exists(fileLocation)) 
     fileLocation = Server.MapPath(string.Format("~/js/{0}", filename)); 

    return JavaScript(System.IO.File.ReadAllText(fileLocation)); 
} 

基本就产生JavaScript文件定制CMS解决方案的过程中,它会检查当前网站文件夹以查看如果Javascript文件存在,如果它不存在,它会尝试从根js文件夹加载它,而所有url看起来像文件位于同一个文件夹中

对文件的调用通常适用于第一次,有时甚至是多次,但是随机地没有改变任何东西,我开始从Firefox获得消息 enter image description here Chrome会显示此消息 enter image description here 当我尝试从提琴手响应解码,我得到这个消息 enter image description here

我才能真正困惑是怎么回事,什么我需要做什么来解决这个问题

+0

似乎像编码的一些问题..你在IIS中使用Http响应压缩或使用一些HttpModule .. –

+0

不使用任何HttpModule,直接IIS –

+1

以及什么是幻数? – shanabus

我结束了在网站上禁用静态和动态内容压缩IIS和它开始工作,不知道为什么它会一直有时并没有将其压缩其他人,仍然会深入挖掘问题,当我得到时间

我并不确定你为什么会遇到编码/解码错误,但我曾在一个团队中以不同的方式解决了类似的问题。

public ActionResult Index(string file, bool? compress) 
{ 
    List<string> requestedFiles; 
    if (file == "documentation") 
    { 
     var path = Server.MapPath("~/Views/Javascript"); 
     requestedFiles = Directory.GetFiles(path, "*.js").Select(x => Path.GetFileNameWithoutExtension(x)).ToList(); 
     return View(file, requestedFiles); 
    } 

    requestedFiles = file.Split(',').Select(x => x.Trim()).ToList(); 

    var javascript = new StringBuilder(); 
    foreach (var filePath in requestedFiles) 
    { 
     using (var fs = new FileStream(Path.Combine(Server.MapPath("~/Views/Javascript"), filePath + ".js"), FileMode.Open)) 
     { 
      var bytes = new byte[fs.Length]; 
      fs.Read(bytes, 0, bytes.Length); 
      javascript.AppendLine(Encoding.UTF8.GetString(bytes).Replace("~/", FullyQulifiedPathToRoot())); 
     } 
    } 

    var compressed = javascript.ToString(); 

    if (!compress.HasValue || compress == true) 
    { 
     compressed = JavaScriptCompressor.Compress(javascript.ToString(), true, true, true, false, int.MaxValue, Encoding.UTF8, CultureInfo.CurrentCulture, false); 
    } 

    return JavaScript(compressed); 
} 

private string FullyQulifiedPathToRoot() 
{ 
    return System.Web.HttpContext.Current.Request.Url.Scheme + "://" + System.Web.HttpContext.Current.Request.Url.Host + VirtualPathUtility.ToAbsolute("~/"); 
} 

这确实需要使用的Yahoo.Yui.Compressor dll

+0

谢谢,我会检查出来,当我今天晚上回家 –

+0

嗯...没有什么不同。我可能尝试连接YUI压缩机,看看是否不能解决我的压缩问题......这是令人沮丧的 –