【发布时间】:2016-12-29 15:13:52
【问题描述】:
我正在尝试使用 serviceworker gem 将 service worker 添加到我的 Rails 应用程序中。
我一直在关注本指南 https://rossta.net/blog/offline-page-for-your-rails-application.html 并开始收到标题中列出的错误。
我查看过其他类似的问题,但大多数是由于语法错误。正如这篇文章Rails 5 Heroku deploy error: ExecJS::ProgramError: SyntaxError: Unexpected token: name (autoRegisterNamespace)
我的错误是由于通过 serviceworker gem 文件提供的令牌名称(catch)。
这是我发生错误的代码...
function onFetch(event) {
// Fetch from network, fallback to cached content, then offline.html for same-origin GET requests
var request = event.request;
if (!request.url.match(/^https?:\/\/example.com/) ) { return; }
if (request.method !== 'GET') { return; }
event.respondWith(
fetch(request). // first, the network
.catch(function fallback() {
caches.match(request).then(function(response) { // then, the cache
response || caches.match("/offline.html.erb"); // then, /offline cache
})
})
);
我知道错误在 .catch ,我只是不确定如何解决这个问题。
非常感谢任何帮助,谢谢!
【问题讨论】:
-
就是这样,fetch 末尾的 (.) 导致了错误。我忽略了它,因为它没有提出任何关于语法问题的问题。谢谢!
标签: ruby-on-rails ruby heroku service-worker