Asp.net 除非存在查询字符串,否则浏览器不会缓存处理程序响应
我已经编写了一个返回javascript的asp.net http处理程序。在html页面上包含引用此处理程序的脚本标记时,chrome/firefox不会报告返回的缓存控件:max age头,除非脚本标记src中存在querystring(或“?”)。因此,处理程序每次都被击中。firefox和chrome都出现了这种情况 以下是处理程序实现:Asp.net 除非存在查询字符串,否则浏览器不会缓存处理程序响应,asp.net,google-chrome,browser-cache,httphandler,cache-control,Asp.net,Google Chrome,Browser Cache,Httphandler,Cache Control,我已经编写了一个返回javascript的asp.net http处理程序。在html页面上包含引用此处理程序的脚本标记时,chrome/firefox不会报告返回的缓存控件:max age头,除非脚本标记src中存在querystring(或“?”)。因此,处理程序每次都被击中。firefox和chrome都出现了这种情况 以下是处理程序实现: Public Overrides Async Function ProcessRequestAsync(context As HttpContext)
Public Overrides Async Function ProcessRequestAsync(context As HttpContext) As Task
Dim loader As New ScriptLoader(context)
Dim sb As New StringBuilder()
sb.Append(Await loader.GetScriptsAsync())
sb.Append(loader.GetLoaderScript("engine"))
sb.Append(loader.GetLoaderScript("styles"))
Dim script As String = sb.ToString()
context.Response.ContentType = "application/javascript"
context.Response.Cache.SetCacheability(HttpCacheability.Public)
context.Response.Cache.SetMaxAge(TimeSpan.FromHours(12))
context.Response.Write(script)
End Function
HTML脚本标记:
<div>
<script src="/ListingDisplay/loader/js"></script>
</div>
结果:
在脚本源上附加“?”时:
<div>
<script src="/ListingDisplay/loader/js?"></script>
</div>
我得到了预期的结果,并且在后续请求中未命中处理程序:
预期结果:
有人见过这个吗?有什么想法吗