Ant*_*ony 5 http http-caching service-worker
在我的网站上,我使用查询字符串参数将信息传递给 Javascript,但返回的实际 html 与查询字符串无关(它只是由 Javascript 动态填充的模板)。
有没有简单的方法可以独立于查询字符串参数来缓存页面?我的一个想法是使用服务工作者从请求中删除查询字符串,但我想知道是否有任何更简单、更干净的方法。
是的,只需缓存非查询参数页面,然后在响应事件时fetch,传递一个附加选项来cache.match(request, options)调用:
return cache.match(event.request, {ignoreSearch: true})
.then(function (response) {
// resolves with the match regardless of query string
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1800 次 |
| 最近记录: |