节点http服务器不提供更新的html文件 [英] node http-server not serving updated html files

查看:159
本文介绍了节点http服务器不提供更新的html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个有角度的前端Web应用程序(主要是ui-router),并通过节点

I am building out a front-end web app with angular (mostly ui-router) and doing local development by serving the html files through node http-server. I have noticed that http-server isn't serving my static html files when I make updates, which is challenging to my local development.

我已经用npm install http-server -g全局安装了http服务器,并通过转到根项目文件夹并运行http-server来启动它.默认值为localhost:8080-似乎可行的两种方法是在每次更新后更改端口号或进入chrome隐身模式.

I have http-server installed globally with npm install http-server -g and start it up by going to the root project folder and running http-server. It defaults to localhost:8080- the two ways that seem to work is changing the port number after each update or going through chrome incognito mode.

有没有一种方法可以正常使用http-server而不必更改端口或使用隐身模式?

Is there a way to use http-server normally without having to change the port or using incognito mode?

如果相关,我正在使用MBP v.10.11.3

If it is relevant, I am using MBP v. 10.11.3

谢谢!

推荐答案

似乎可行的两种方法是在每次更新后更改端口号或进入chrome隐身模式.

the two ways that seem to work is changing the port number after each update or going through chrome incognito mode.

您的问题是客户端缓存.隐身模式具有自己的数据目录,与您的正常浏览无关.

Your problem is client-side caching. Incognito mode has its own data directory, independent from your normal browsing.

幸运的是,http服务器为您提供了一种设置缓存控制标头的方法.

Fortunately, http-server provides a way for you to set the cache control headers.

-c设置缓存控制最大使用时间标头的缓存时间(以秒为单位),例如-c10 10秒钟(默认为"3600").要禁用缓存,请使用-c-1(可能还使用-p 8080强制服务器清除该端口的缓存;可以在以后的运行中将其删除).

-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

It's listed in the documentation here: https://github.com/indexzero/http-server

您可以在此处阅读HTTP缓存指令: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=zh-CN

You can read up on HTTP caching directives here: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en

这篇关于节点http服务器不提供更新的html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆