Optimize web performance with cached HTTP route responses
TL;DR: Use the Cache-Control header with the public directive on HTTP route responses in Gadget to cache response data in Gadget’s CDN
Fine-tuning HTTP response performance is a crucial endeavor that can have a major impact on user experience. It’s important that users get their data fast, and caching response payloads can provide a big performance boost, especially for long-running queries.
To help developers optimize performance and provide the best user experience, Gadget now supports caching responses from HTTP routes using a high-performance, pre-configured CDN. If your route serves a Cache-Control header, the response will be cached at the edge and sent back to your users as you see fit.
For example, you can make a route cache its response in Gadget's CDN by setting the Cache-Control header in your route using the public directive:
A brief introduction to Cache-Control
Generally, browsers will not cache data without the Cache-Control header, which, when added to HTTP responses, empowers web developers by allowing them to optimize website performance and enhance user experiences by controlling caching behavior. With Cache-Control, websites can reduce server load and bandwidth usage by instructing browsers and intermediaries, Gadget’s CDN in this case, to cache resources, resulting in faster page loads for returning visitors. It also allows for fine-grained control over which resources should or should not be cached, mitigating potential data leakage or security risks. By fostering efficient content delivery, and reducing latency and server round-trips, it allows developers to contribute to a more responsive and scalable web ecosystem.
Want to learn more about using Cache-Control in HTTP route responses? Read our documentation or ask questions in our developer Discord.