Suped

What are the best practices for using comments in publicly viewable email HTML code?

Summary

Using comments in publicly viewable email HTML code is a nuanced topic that balances the need for developer readability with concerns about security, file size, and deliverability. Unlike web pages that often undergo build processes to strip comments, email HTML is typically sent as-is, meaning anything in your source code can be viewed by recipients who inspect the email. This can introduce unnecessary bloat and, more critically, potential security vulnerabilities. Therefore, a disciplined approach to comments is essential.

What email marketers say

Email marketers often focus on the visual rendering of their campaigns and the metrics that drive business outcomes, rather than the intricate details of the underlying HTML code. While they may not directly manage code comments, the impact of these comments, particularly on file size and potential security issues, can indirectly affect their campaigns, including deliverability and user experience. Understanding these implications is key for effective collaboration with development teams.

Marketer view

Email marketer from DEV Community highlights that comments in HTML should be clear and concise. They serve as valuable notes for developers to understand the code's purpose or specific logic applied. However, this advice primarily applies to development environments where clarity and collaboration are paramount, rather than the final publicly distributed code.

22 Jan 2024 - DEV Community

Marketer view

Marketer from CRONUTS.DIGITAL advises prudence when adding HTML comments, stating that one should not comment merely for the sake of it. The key is to assess whether the comment genuinely adds value and contributes to a better understanding of the code. This implies that comments should be purposeful and not simply decorative elements within the HTML structure.

15 Feb 2024 - CRONUTS.DIGITAL

What the experts say

Email deliverability experts take a strong stance on the use of comments in publicly visible email HTML. Their primary concern revolves around security vulnerabilities, potential performance degradation, and the overall professionalism of the code. They advocate for rigorous development and deployment processes that ensure no extraneous or sensitive information is accidentally exposed through comments.

Expert view

Email expert from Email Geeks suggests that publicly viewable code should have minimal comments, if any. The rationale is that there is typically no good reason to include them in production environments. Any comments present in the final HTML code are effectively exposed to anyone who inspects the email, which can be an unnecessary risk.

20 Dec 2017 - Email Geeks

Expert view

Deliverability expert from Word to the Wise (Matt Bailey) emphasizes that comments should clarify the 'why' behind a code choice, not simply the 'what'. This distinction is crucial, as explaining motivation can be valuable during development, but such commentary should not make it into publicly accessible code. Effective documentation should reside elsewhere, in version control or internal wikis, ensuring code remains lean and secure.

10 Apr 2023 - Word to the Wise

What the documentation says

Official documentation and developer guides provide the foundational understanding of HTML comments. They explain the syntax, purpose, and general best practices for their use. However, these resources often focus on broad web development principles and may not explicitly address the unique considerations of email HTML, where public visibility and file size have disproportionate impacts on deliverability and user experience.

Technical article

Developer documentation from MDN Web Docs explains that HTML comments can be placed in various locations within a document, including before and after the Doctype declaration, and within body content. They function primarily as internal notes for developers and are ignored by the browser during rendering. While flexible in placement, their presence in live code adds unnecessary characters that contribute to file size and can be easily viewed by anyone inspecting the source.

10 Apr 2024 - MDN Web Docs

Technical article

A guide from DEV Community on HTML comments and best practices emphasizes that comments should be clear and concise. This guideline ensures that internal documentation within the code remains helpful to developers. However, for publicly viewable code, such detailed comments can become a liability, suggesting that this clarity is best confined to development or internal versions.

22 Jan 2024 - DEV Community

8 resources

Start improving your email deliverability today

Get started