首页 > 解决方案 > Node js / Express js form do not expire after posting data

问题描述

First and foremost I would like to inform you that I am new to node js!

I have been asked to implement a simple application in node js. So, I have created a form that submits via POST method its data. When data are retrieved and processed I render another page in order to display some info regarding the submitted data and the results of the whole process.

My problem is that users are able to click the back button from the browser, load the submitted data again and re-press the submit button.

It sounds stupid but I'am stuck in here for days...

Thanks in advance.

标签: node.jsexpress

解决方案


这是由于各种浏览器的HTTP 缓存策略:FireFox 中的“后向缓存”(BFCache);Safari等中的“页面缓存”。它是为了优化导航速度而实现的。本质上,它缓存了整个页面的 DOM,包括非 HTTPS 站点的表单元素。可以通过侦听加载页面的事件或通过使用来自服务器的HTTP 标头不缓存该页面(例如Cache-Control: no-cache, max-age=0, must-revalidate, no-store)来以编程方式清除表单元素。

Cache-Control在 Express 中设置响应的标头,请使用set响应对象的方法:

res.set('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');

推荐阅读