简体   繁体   中英

HTML file as a js or css

I know this is a stupid question.

But just out of curiosity, is there a way to post an html file(a .html file) as a js/css file (renamed as .js or .css) with the type header as either HTML or js/css and get the data at the browser end in normal html format? I mean the browser reading it as an html itself and display it as any other html page?

What matters for the browser when displaying a resource is the Content-Type HTTP header. As long as this header is set by the web server to text/html , the extension doesn't really matter. The resource will be interpreted as HTML. So you could configure the web server to serve .js file with a text/html Content-Type and it will work.

The file doesn't even need to exist on the server. That's why I prefer to talk about resources instead of files. You could use a server side language and configure it to respond to some virtual address (with the .js extension) and serving HTML content with the text/html Content-Type header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM