关于koa-static-cache这些文件缓存的问题

发布于 2022-09-11 16:26:16 字数 213 浏览 8 评论 0

我没有加载koa-static-cache这个中间件,渲染图片会不出来。请问为啥要有静态资源服务器,没有的话图片路径有问题

还有下面这张图片这个文件缓存为什幺要分成两个目录来写,单独写一个还不行。文件路径是public文件夹下面有个images文件夹

图片描述

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临风闻羌笛 2022-09-18 16:26:16

https://www.npmjs.com/package...
如果你是要访问图片的话,不应该用koa-static-cache,而是用koa-static。

项目根目录下新建 public/images

const static = require('koa-static');    //静态资源服务
const  staticPath = './public';  // 配置静态资源文件根目录
app.use(static(
    path.join( __dirname, staticPath)
));

这样子你访问图片 public/images/1.jpg 是这样子的 localhost:8080/images/1.jpg

她说她爱他 2022-09-18 16:26:16

请看官方 README.md 开头所写的内容。

Static server for koa.

Differences between this library and other libraries such as static:

* There is no directory or index.html support.
* You may optionally store the data in memory - it streams by default.
* Caches the assets on initialization - you need to restart the process to update the assets.(can turn off with options.preload = false)
* Uses MD5 hash sum as an ETag.
* Uses .gz files if present on disk, like nginx gzip_static module

因此,你这里显然应该使用 koa-static 而不是 koa-static-cache。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文