My original setup, as described in [[MDX Blog Post]], was to compile MDX at load time. This resulted in slow client-side performance. I needed to find a way to improve the compile speeds.
First I updated the loader function in my app/routes/$slug.tsx file to check the post version number. If the version number of the post and the version number in the database match, the loader function will return the cached post. If the version numbers do not match, the loader function will compile the MDX and update the cache.
Next, I created a cache manager to handle the caching of the MDX pages. The cache manager is responsible for storing and retrieving the cached MDX pages from the database.
After implementing the cache system, the compile speeds of my MDX pages improved significantly. The client-side performance is now in the tens of milliseconds vice the seconds it was before. I am very happy with the results and will continue to monitor the performance of my site. I still need to tackle connection issues with my database due to "cold starts" and uploading posts without having to re-build my entire project. I will continue to work on these issues in the future and update you on my progress.