简体   繁体   中英

Check if viewed source not render

Is there a way to check if the current request was for page source (HTML) not actual site?

And if not (which I think is the case), is there a way I could somehow "parse" this out of request parameters and maybe times or something?

I need this to display real source when viewing it, and trimmed one when rendering it..

Is there a way to check if the current request was for page source (HTML) not actual site?

No. The request is always for the page source. There is no way to distinguish what the browser is going to do with it.

Also, many browsers (like IE) can't make a request for "view source" at all - you always load the whole site, render it, and then do a "view source".

Workaround ideas: (All terribly flawed)

  • Add some JavaScript to the page making an Ajax call. If the call is made, the page was rendered.

  • Add some image resource to the page. If it's loaded, the page was rendered.

If this is to protect your HTML source code, forget it and go do something productive instead. :)

It sounds like you're wanting to send optimized/compressed/bandwidth-friendly code when it's being viewed in the browser, and readable/understandable/indented code if the user is wanting to view the source code, right?

Unfortunately, that's not possible, and I suspect it would be counter-productive, since it would prevent you from debugging problems if your Javascript minimizer or HTML compressor code was introducing problems. It would be far better to use something that reintroduces whitespace and indentation for readability. For example, the View Source Chart extension for Firefox. (I don't know what options there are for unminimizing Javascript code.)

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