我正在构建一个带有 Angular (主要是 ui-router)的前端网络应用程序,并通过 Node http-server 提供 html 文件来进行本地开发。 .我注意到当我进行更新时,http-server 不提供我的静态 html 文件,这对我的本地开发来说是一个挑战。
我使用 npm install http-server -g
在全局安装了 http-server 并通过转到根项目文件夹并运行 http-server
来启动它。它默认为 localhost:8080 - 两种似乎有效的方法是在每次更新后更改端口号或通过 chrome 隐身模式。
有没有一种方法可以正常使用http-server,而无需更改端口或使用隐身模式?
如果相关,我使用的是 MBP v. 10.11.3
谢谢!
最佳答案
the two ways that seem to work is changing the port number after each update or going through chrome incognito mode.
您的问题是客户端缓存。隐身模式有自己的数据目录,独立于您的正常浏览。
幸运的是,http-server 为您提供了一种设置缓存控制 header 的方法。
-c
Set cache time (in seconds) for cache-control max-age header, e.g.-c10
for 10 seconds (defaults to '3600'). To disable caching, use-c-1
(and possibly-p 8080
to force the server to clear the cache for that port; can be removed on subsequent runs).
它在此处的文档中列出:https://github.com/indexzero/http-server
您可以在这里阅读 HTTP 缓存指令:https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en
关于angularjs - Node http 服务器不提供更新的 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38295463/