缓存 html 忽略查询字符串
Cache html ignoring query string
在我的站点上,我使用查询字符串参数将信息传递给 Javascript,但实际返回的 html 与查询字符串无关(它只是一个填写的模板动态地 Javascript)。
有什么简单的方法可以独立于查询字符串参数来缓存页面吗?我的一个想法是使用 service worker 从请求中剥离查询字符串,但我想知道是否有任何更简单、更清晰的方法。
是的,只需缓存非查询参数页面,然后在响应 fetch
事件时,将附加选项传递给 cache.match(request, options)
调用:
return cache.match(event.request, {ignoreSearch: true})
.then(function (response) {
// resolves with the match regardless of query string
});
在我的站点上,我使用查询字符串参数将信息传递给 Javascript,但实际返回的 html 与查询字符串无关(它只是一个填写的模板动态地 Javascript)。
有什么简单的方法可以独立于查询字符串参数来缓存页面吗?我的一个想法是使用 service worker 从请求中剥离查询字符串,但我想知道是否有任何更简单、更清晰的方法。
是的,只需缓存非查询参数页面,然后在响应 fetch
事件时,将附加选项传递给 cache.match(request, options)
调用:
return cache.match(event.request, {ignoreSearch: true})
.then(function (response) {
// resolves with the match regardless of query string
});