Converting dynamic pages to static for better performance and... Happy Christmas!
Written by Richard Heyes, RGraph author, on 22nd December 2025In my never-ending quest to get the best performance possible out of the website, many of the pages' output is now cached on the server. This output is then used, if it exists, in place of the dynamic page. So what you're loading is just a static HTML page instead of a dynamic server-built page (not that there was a lot involved in the building anyway).
There's an admin panel behind the scenes that calls the dynamic page, takes the resulting HTML and then writes that HTML to a file. When you load the page in your browser, that file is used, if it exists, in favour of the original script, so you're loading the static file instead of the original script.
The admin panel that loads the original script and then writes the HTML to a file was simple enough to build and then there was a bit of Apache configuration that had to go in a .htaccess file that makes the server use the static HTML file instead of the original script, and that looks like this:
## ## Rules to make Apache use static content if it exists in favour ## of the original script. ## # This makes the rewrite conditional on the static file existing. RewriteCond %{REQUEST_FILENAME}.static -f # The rewrite rule which tells Apache to use the static version of # the file if it exists. RewriteRule (.*).html$ /$1.html.static [L] # This block matches the .static files that have been generated by # the admin panel and saved alongside the original script. <filesMatch "\.html\.static$" > # Add a Cache-Control header to the output that makes the user's # browser cache the page header set "Cache-Control" "public, private, max-age=604800" # Make the HTML page completely static and not use server-side # scripting for maximum speed RemoveHandler .html </FilesMatch>
So there's not much in the way of configuration involved in trying to attain the best possible performance. Obviously, this solution would not fit a fully dynamic site - something as simple as a logged-in users name in the top right of the page would make a dynamic page necessary - though you could cook something up where the main page is static but the "logged-in" bit of the page (which might state the users name for example) is done by an AJAX script (which, obviously, wouldn't be static).
And since we're a few days away from Christmas, I'd better say the obligatory "Happy Christmas"! If you're celebrating it then have a great time and if not - then don't worry too much about it! Just enjoy the time off work if you have it. :-)