【问题标题】:Cache html ignoring query string缓存 html 忽略查询字符串
【发布时间】:2016-12-06 18:24:53
【问题描述】:

在我的网站上,我使用查询字符串参数将信息传递给 Javascript,但返回的实际 html 与查询字符串无关(它只是一个由 Javascript 动态填充的模板)。

是否有任何简单的方法可以使页面缓存独立于查询字符串参数?我的一个想法是使用服务工作者从请求中去除查询字符串,但我想知道是否有任何更简单、更清洁的方法。

【问题讨论】:

    标签: http service-worker http-caching


    【解决方案1】:

    是的,只需缓存非查询参数页面,然后在响应fetch 事件时,将附加选项传递给cache.match(request, options) 调用:

    return cache.match(event.request, {ignoreSearch: true})
        .then(function (response) {
            // resolves with the match regardless of query string
        });
    

    MDN docs for Cache.match parameters

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      相关资源
      最近更新 更多