Home >Web Front-end >JS Tutorial >Should HTML Comments Still Be Used Inside Script Tags?
Should HTML Comments Be Used Inside Script Tags?
In earlier days, HTML comments were employed within script tags to hide JavaScript code from browsers that didn't support it. However, this practice is no longer considered a best practice for modern browsers.
Nowadays, nearly all widely used browsers have support for script blocks, enabling them to ignore JavaScript code even if it's not interpreted. Therefore, the purpose of using HTML comments to conceal the code is obsolete.
Expert Matt Kruse on his JavaScript Toolbox website explains why it's specifically discouraged to utilize HTML comments in script blocks.
According to Kruse, this practice:
Therefore, it's recommended to refrain from using HTML comments inside script tags to avoid potential issues and maintain code clarity.
The above is the detailed content of Should HTML Comments Still Be Used Inside Script Tags?. For more information, please follow other related articles on the PHP Chinese website!