简体   繁体   English

是否可以阻止标准HTML注释显示在源代码中?

[英]Is it possible to prevent standard HTML comments from showing up in source code?

I'm going to assume the answer is 'no' here, but since I haven't actually found that answer, I'm asking. 我将在这里假设答案是'不',但由于我实际上没有找到答案,我问。

Quite basically, all I want to do is leave some HTML commenting in my files for 'author eyes only', simply to make editing the file later a much more pleasant experience. 基本上,我想要做的就是在我的文件中留下一些HTML评论“仅限作者眼睛”,只是为了让以后编辑文件更加愉快。

<!-- Doing it like this --> leaves nice clean comments but they show up when viewing the page source after output. <!-- Doing it like this -->留下很好的干净注释,但是在输出后查看页面源时会显示它们。

I am using PHP, so technically I could <?PHP /* wrap comments in PHP tags */ ?> which would prevent them from being output at all, but if possible I'd like to avoid all of the extra arbitrary PHP tagging that would be needed for commenting throughout the file. 我正在使用PHP,所以从技术上来说,我可以<?PHP /* wrap comments in PHP tags */ ?>这将阻止它们输出,但如果可能的话,我想避免所有额外的任意PHP标记将需要在整个文件中进行评论。 After all, the point of commenting is to make the document feel less cluttered and more organized. 毕竟,评论的目的是使文档更简洁,更有条理。

Is there anything else I could try or are these my best options? 还有什么我可以尝试或者这些是我最好的选择吗?

No, anything in html will show up. 不,html中的任何内容都会显示出来。

You could, have a script that parses the code, and removes the comments, before it puts it up on the server, and then you would have the original, and the uncommented source. 您可以拥有一个解析代码的脚本,并在将注释放入服务器之前删除注释,然后您将拥有原始注释和未注释的源。

A tool to accomplish this: http://code.google.com/p/htmlcompressor/ 完成此任务的工具: http//code.google.com/p/htmlcompressor/

I guess these are your best options, yes, unless you run the entire HTML output through some sort of cleanup module before being sent to the client. 我想这些是你最好的选择,是的,除非你在发送到客户端之前通过某种清理模块运行整个HTML输出。

Anything not wrapped in server side syntax will will be output to the client if not modified on its way out (through template engines, for example). 如果未在服务器端语法中进行修改(例如,通过模板引擎),则任何未包含在服务器端语法中的内容都将输出到客户端。 This goes for most (probably all) server side languages). 这适用于大多数(可能是所有)服务器端语言)。

你绝对可以编写一个使用正则表达式来删除HTML注释的解析器,但除非你已经在处理自己动手的CMS,否则很可能在这方面所涉及的工作超过了你不建议使用PHP注释的好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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