Can we add http response headers directly into html pages

此生再无相见时 提交于 2019-12-24 03:48:10

问题


I need to add response headers like X-Frame, Cache-control, Pragma etc directly into the html code, may be, using attributes in html elements?

It is for help pages which are directly coming from a directory via href link.

Is there any way to add headers to these htmls?


回答1:


You can use meta to replicate some of these. Normally not the ideal solution, but look into the http-equiv attribute of meta tags. I believe a lot of these have been deprecated in newer browsers.

Examples:

<meta http-equiv="Cache-control" content="no-cache"/>

<meta http-equiv="X-Frame-Options" content="sameorigin"/>

<meta http-equiv="pragma" content="no-cache"/>



回答2:


In short: no, you cannot. HTML files are the body of an HTTP response; the headers must come from the server. Anything you could embed in the HTML file would just become part of the body.



来源:https://stackoverflow.com/questions/36159391/can-we-add-http-response-headers-directly-into-html-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!