Static HTML Generation Finished
Published 08/17/2024
📝 Click here for a more in-depth look at the code behind the generator
When I started this site, I designed the platform in a way where the pages could be served as static html. Practically, this meant no login system, and guest-only pages.
Up until today, I was serving everything dynamically - even though all page requests were cached after first visit. This worked but the end goal has always been to create a static-html generator.
To generate the static pages, all we’re really doing is simulating that initial request for every page.
The other change I made is to add two ways of serving pages, dynamic and static.
dynamicmode means the pages are served by the platform. (Cookies, headers, GET / POST)staticmode means the pages are written to disk, built as static html pages. These can then be served by any webserver at this point.
The obvious benefit to serving the pages as static HTML in my mind is the ability to serve every page using a CDN.
- Another benefit is GitHub Pages offers free hosting for websites that are entirely static.
The plan for production is to use the platform a build tool, deploying static HTML behind a CDN. I won’t be deploying the platform in dynamic mode, this mode is for development / writing. I also won’t be deploying it in static mode, this mode is for testing.
Static HTML Generation
//create new request
ClientBuffer buffer = new ClientBuffer();
buffer.request = new Request("", Request.RequestType.GET, fileName, "", new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
//store page contents after processing the page
byte[] pageContents = webPage.processPage(buffer);
//output file
File file = new File("./out" + fileName + ".html");
//create parent directories
file.getParentFile().mkdirs();
//write file
DiskWriter.write(file, pageContents);