简体   繁体   English

我们如何控制 OSGI 上资源的网页缓存?

[英]How do we control web page caching for resources on OSGI?

我需要缓存来自 AEM 的资源(图像和字体)。使用 SlingHttpServletRequest 我可以获取所有资源路径。所以我如何将实际资源放入浏览器缓存中。我使用 slingResponse.setHeader() 检查它。但仍然是找不到将资源路径放入浏览器缓存的方法。

Browser cache is controlled using Cache-Control headers.浏览器缓存是使用Cache-Control标头控制的 This ideally needs to be set up on the dispatcher.理想情况下,这需要在调度程序上设置。 On a standard set up dispatcher isn't configured to cache response headers.在标准设置中,调度程序未配置为缓存响应标头。 So any headers set on the server will not be used for subsequent requests when it is served from cache.因此,当从缓存中提供服务时,服务器上设置的任何标头都不会用于后续请求。

Use the mod_headers module on the dispatcher to send out max-age or expires values for the files you are interested in.使用调度程序上的mod_headers模块为您感兴趣的文件发送 max-age 或 expires 值。

Ex: To cache all static resources for 1 year on the browser use例如:在浏览器使用时缓存所有静态资源 1 年

<LocationMatch "^\/etc\/designs\/my-project\/clientlibs-site\/(css|images|fonts|placeholders)\/.*">
  Header set Cache-Control "public, max-age=31536000"
</LocationMatch>

On encountering the cache control headers browsers will cache the resources.遇到缓存控制标头时,浏览器将缓存资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM