I would like to cache one of controllers action (which result is dynamically rendered javascript code), so i have added this annotations:
/// <summary>
/// Renders embed client javascript.
/// </summary>
/// <param name="minify">True for minifing script</param>
/// <returns>Javascript result.</returns>
[HttpGet]
[ActionName("xtech.embed.client.js")]
[OutputCache(Duration = 3600, VaryByParam = "minify")]
public ActionResult ClientScript(bool minify = false)
On the first request i get response headers:
cache-control:public, max-age=1812
content-length:23336
content-type:application/x-javascript; charset=utf-8
date:Tue, 06 Mar 2018 13:12:50 GMT
expires:Tue, 06 Mar 2018 13:43:03 GMT
last-modified:Tue, 06 Mar 2018 12:43:03 GMT
server:Microsoft-IIS/10.0
status:200
vary:*
Second run goes with response header:
cache-control:public, max-age=1670
date:Tue, 06 Mar 2018 13:15:11 GMT
expires:Tue, 06 Mar 2018 13:43:03 GMT
last-modified:Tue, 06 Mar 2018 12:43:03 GMT
server:Microsoft-IIS/10.0
status:304
vary:*
This means that each subsequent request browser queries server for resource modification. I would like to change this behavior so that resource would be restored from browser cache without query the server till cache expiration.
Do you know if this can be done with data attributes or requires custom cache options and some extra code?
Note: Cache configuration (inside webconfig) for static files like: How to specify HTTP expiration header? (ASP.NET MVC+IIS) cannot be used because result is dynamic (view rendered javascript).