Story Details

  • Why can't HTML alone do includes?

    Posted: 2025-05-03 12:50:55

    HTML is designed for structuring content, not for complex logic like file inclusion. Including external files requires fetching and parsing them, a task handled by the server (server-side includes) or the browser (client-side JavaScript). While templating languages and build tools can pre-process HTML with includes, native HTML lacks the capability because it prioritizes simplicity, performance, and security. Implementing includes directly in HTML would introduce significant complexity, potentially impacting rendering speed and opening up security vulnerabilities if HTML files could arbitrarily execute external scripts. Therefore, the responsibility of assembling the final HTML document typically falls to other tools and technologies better suited to handle the complexities involved.

    Summary of Comments ( 170 )
    https://news.ycombinator.com/item?id=43878728

    Hacker News users discuss the limitations of native HTML includes and the reasons behind them. Several commenters point to the complexity of implementing a robust include system within the browser, particularly regarding caching, dependency management, and potential security vulnerabilities. One highly upvoted comment suggests that the desire for includes often stems from a misunderstanding of HTML's purpose as a document format, not a programming language. Others argue that server-side includes (SSI) and build tools effectively address the need for modularity during development, making browser-native includes unnecessary. The lack of standardization and potential performance issues are also cited as reasons for the absence of this feature. Some commenters express a preference for using JavaScript and build tools, while others lament the added complexity this introduces. The historical context of frames and iframes is also brought up, highlighting their shortcomings and why they aren't suitable replacements for true includes.