问题描述
我有一个 Vue 应用程序在带有 Nginx 的 VPS Debian 服务器上运行。 我使用缓存 API 缓存数据并将其加载到应用程序中。 当应用程序上传到我的 ftp 时,它运行良好,但在我将其部署到服务器上之后, 我收到一个错误:
Uncaught (in promise) ReferenceError: caches is not defined
运行缓存api的代码是:
const getCachedResource = async (type) => {
const url = `${DATA_URL}${type}.json`
const cache = await caches.open(cacheName);
if (cache) {
const response = await cache.match(url)
if (!response) {
return undefined
}
const jsonResponse = await response.json()
return jsonResponse
}
}
我需要在 VPS 上启用/修复什么才能让它运行吗?
解决方法
问题在于缓存 API 需要 HTTPS。当我添加证书时,问题得到解决。