angularjs - Node http 服务器不提供更新的 html 文件

标签 angularjs node.js httpserver

我正在构建一个带有 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/

相关文章:

AngularJS:如何在 Angular 应用程序中嵌套应用程序

javascript - 使用 node.js 将数据显示到从 mongodb 检索的网页中

node.js - 如何使用 Elastic Beanstalk 设置 AWS CDK 的环境变量?

node.js - 如何将环境变量设置为 gulp 任务?

python - 从监听套接字/HTTPServer 获取传入 URL

java - 如何使用HttpServer类将8000端口暴露给远程访问?

javascript - 为什么我从 jQuery 和 HttpHandler 获取 html 标签?

javascript - 如何在选中另一个复选框时取消选中默认复选框 - Angular

angularjs - Angular 翻译

javascript - 手动引导 Angular 与 http 调用