1

私はJavascriptvaiに次のようなコントローラーメソッドを提供しています:

  [OutputCache(Duration = 120)]
  [Compress]
  public ActionResult JavascriptFile(String scriptName) {
     string content;
     if (HttpContext.IsDebuggingEnabled) {
        content = ReadApplicationScript(string.Format("~/scripts/{0}", scriptName));
        return Content(content, "application/javascript");
     }
     else {
        content = ReadApplicationScript(string.Format("~/scripts/Built/{0}", scriptName));
        return Content(content, "application/javascript");
     }
  }

Compress属性はここからです

ySlowを実行すると、「Expiresヘッダーの追加」でFグレードを取得します。これらを追加するにはどうすればよいですか?

4

1 に答える 1

2

system.webServerセクション内に次を追加します

<staticContent>
      <clientCache cacheControlMode="UseExpires"
         httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
    </staticContent>

ここで、httpExpires値は有効期限になります。

編集

次のように、コンテンツをキャッシュに追加してみることもできます。

var cacheName = "someName";
var value = HttpRuntime.Cache.Get(cacheName) as ContentResult;

            if (value == null)
            {                
                var contentResult = ReadApplicationScript(string.Format("~/scripts/{0}",scriptName));
                System.Web.HttpContext.Current.Cache.Insert(cacheName, contentResult );
                return contentResult;
            }

            return value;
于 2012-10-11T04:23:52.497 に答える