Server Side Includes (SSI) with CloudFlare Workers


I opened this issue a while ago,, does anyone have a way to do server side includes with Workers?

I just want a way to load in header/footer without having to maintain 10+ files with their own versions of each.


I found a way to do it, even if it isn’t ideal.

On the client side,

<body onload="getHeader()">

  function getHeader() {
    var req = new XMLHttpRequest();
    req.onreadystatechange = displayHeader;"GET", "/header.html");

    function displayHeader() {
      if (req.readyState != 4) return; 
      document.getElementById("header").innerHTML = req.responseText;

<div id="header"></div>

will grab the header from the appropriate place, and render it within the “header” div. It isn’t ideal to be doing this on the client side, but it works well enough and workers is fast enough that it doesn’t effect loading times much.

1 Like