4
We all know the good old HTML comments:
<!-- Oi, eu sou o Goku! -->
The point is: there is some way to delete HTML comments that the server sends to the client? I think such configuration is done at the server level (I am specifically below IIS), but programming-based solutions are also welcome (I think something in the global routines: Global.asa
- for ASP scripts - or Global.asax.cs
- for ASP.NET pages - be also suitable).
The need arose recently in the company where I work, because there are several HTML comments - sent therefore to the client - with negotiation details of the functioning of the routines, and these comments should have been made with their respective versions server side
, to be ignored during the build process.
I don’t think there’s any solution as you imagined. In my opinion the simplest alternative would be to convert such comments into comments of the server-side type using for example Visual Studio’s Find and Replace option.
– iuristona
@iuristona at first thought about it too, but I decided to ask anyway! If it is something that can be solved by the server, it would be one less concern when indoctrinating the team. Anyway, thank you for participating
– Tiago César Oliveira
Even if there is a way to process and remove on the server (an HTML parser would do that), I don’t think it’s worth burdening all requests with this filtering. The ideal would be some kind of script that actually changes the source files, completely removing the comments or converting them to a server-side version.
– bfavaretto
Good argument, @bfavaretto! I had not thought from this perspective.
– Tiago César Oliveira
Of course it is possible! In PHP, for example, just use the function
ob_start
to pick up the content of the page before it is sent andpreg_replace
to remove HTML comments. But in ASP I don’t know how to do it. Search here: https://www.google.com/search?q=asp+ob_start+like– user622
The @bfavaretto suggestion is the best one. Pre-process all your content by removing comments. PS: Someone please edit the post. The correct comment would be
<!-- Oi, eu sou o Goku! -->
.– OnoSendai
@Onosendai done ;-)
– Tiago César Oliveira
@Tiagocésaroliveira perfect, thank you. =)
– OnoSendai
@Gabrielsantos agrees with you, but I also agree that the ideal would be to pre-process the files to avoid unnecessary processing. I am already here working on a regex that allows me to work with a parser in order to solve this. When finished, I share here the implementation.
– Tiago César Oliveira
@Tiagocésaroliveira Yes, but if you have many files, will give a job to do it in hand. With a regex, the process is automatic. In addition, it is possible to save Bandwidth by removing spaces and line breaks. I always do this by leaving HTML in one line. You know.
– user622
@Gabrielsantos what I’m trying to do is an executable that reads file to file, locates the comments via regex and turns them into server side comments. This way I save pre-processing before serving the page
– Tiago César Oliveira