Typolino – Cache Control

To improve the UX it is important to serve content as fast as possible. The Firebase hosting is pretty clever, but the images we serve from the storage has a default cache configuration that disallows caching the content. We can control the cache-control header when uploading the images.

   bucket.file(imagePath).createWriteStream({
            metadata: {
               cacheControl: 'public, max-age=604800' 
            }
   }
            

This will allow caching the content for 7 days. Sill – accessing the images is quite slow as we first need to get the actual download URL. I wonder whether it would make sense to store the actual URL in the DB so that we can save the additional lookup call. Also we could add some PWA features to preload the images.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.