What is the Cache-Control Header?

What is the Cache-Control Header?

Understanding the Cache-Control Header in VergeCloud

The Cache-Control header is an essential HTTP header used to manage caching behavior for content served on the web. By defining caching directives, the Cache-Control header helps optimize content delivery and ensures that resources are appropriately cached or fetched from the origin server as needed. VergeCloud, as a powerful content delivery network (CDN), respects these directives and ensures optimal caching, reducing latency and improving site performance for users.

How the Cache-Control Header Functions in VergeCloud

The Cache-Control header defines how long content should be cached, where it should be cached (e.g., in browsers or on CDNs like VergeCloud), and under what conditions content should be revalidated. By properly configuring the Cache-Control header, VergeCloud allows for seamless caching across its edge servers to improve website performance and ensure fresh content is delivered to users when necessary.

Complete List of Cache-Control Header Values in VergeCloud

The Cache-Control header can include several directives that dictate how content should be cached and served. Below is a list of commonly used Cache-Control values, along with explanations for each and their examples:

  • max-age:

    The max-age directive specifies the maximum time (in seconds) a resource is considered fresh. After this time, the resource will be treated as stale, and the server will check for updates. Example: Cache-Control: max-age=3600 (caches for 1 hour).

  • public:

    The public directive allows the response to be cached by any cache, including browsers and CDNs. This is typically used for static resources like images, stylesheets, and JavaScript files. Example: Cache-Control: public, max-age=86400 (caches for 24 hours).

  • private:

    The private directive indicates that the response is for a single user and should not be cached by shared caches (like CDNs). Example: Cache-Control: private, max-age=3600 (caches for 1 hour, but only for the user).

  • no-store:

    The no-store directive prevents caching entirely. This is typically used for sensitive data (e.g., banking or login information) where caching is not appropriate. Example: Cache-Control: no-store (no caching).

  • no-cache:

    The no-cache directive indicates that the content may be cached, but it must be revalidated with the origin server before it can be used. Example: Cache-Control: no-cache, max-age=0 (caches for a zero duration, requires revalidation on every request).

  • must-revalidate:

    The must-revalidate directive requires caches to revalidate the content once it becomes stale. Example: Cache-Control: max-age=3600, must-revalidate (forces revalidation after 1 hour).

  • stale-while-revalidate:

    The stale-while-revalidate directive allows stale content to be served while the cache revalidates the content in the background. Example: Cache-Control: max-age=3600, stale-while-revalidate=86400 (caches for 1 hour, allows stale content for up to 24 hours while revalidating).

  • proxy-revalidate:

    Similar to must-revalidate, but specifically for shared caches.

  • stale-if-error:

    The stale-if-error directive allows stale content to be served if there is an error in retrieving fresh content from the origin server. Example: Cache-Control: max-age=3600, stale-if-error=86400 (Serve stale content if there's an error for up to 24 hours.).

  • max-stale:

     Indicates the client will accept a stale response up to the specified time.

  • min-fresh:

    Indicates the client wants a response that will still be fresh for at least the specified time.

  • immutable:

    Indicates that the response will not change and can be cached indefinitely.

  • no-transform:

    Indicates that the resource should not be transformed by intermediate caches.

  • only-if-cached:

     Instructs the cache to respond only if the resource is available in the cache.


Use Cases of Cache-Control Values in VergeCloud

Here are some practical scenarios where different Cache-Control values are used in VergeCloud to optimize content delivery:

  • Public Resources (e.g., static assets):

    For static resources like images, JavaScript files, or CSS, it’s best to use the public directive with a long max-age value to reduce load times and improve performance. Example: Cache-Control: public, max-age=86400 for assets that should be cached for 24 hours across all clients.

  • User-Specific Content (e.g., personalized pages):

    If content is personalized or unique to each user (such as account pages or shopping carts), use the private directive to ensure that the content is cached only for the specific user and not shared across different users. Example: Cache-Control: private, max-age=3600.

  • Sensitive Information (e.g., login pages):

    For sensitive or private information, use the no-store directive to ensure that the content is never cached. Example: Cache-Control: no-store for login forms, banking pages, or user-specific sensitive data.

  • Content that Changes Frequently (e.g., news sites):

    For content that needs to be frequently updated but should still be cached, use the no-cache directive. This ensures the content is always validated before serving it. Example: Cache-Control: no-cache, max-age=0 for news sites where the content may change frequently but caching is still useful.

  • High Traffic Sites (e.g., blogs or popular landing pages):

    For high-traffic sites that don’t change often, but can tolerate slightly outdated content in exchange for reduced latency, use stale-while-revalidate. This allows stale content to be served while the CDN fetches fresh content in the background. Example: Cache-Control: max-age=3600, stale-while-revalidate=86400.

How to Configure the Cache-Control Header in the VergeCloud Panel

To configure the Cache-Control header in VergeCloud, follow these steps:

  1. Log into the VergeCloud user panel.
  2. Go to the Content Delivery Network (CDN) section.
  3. Click on Page Rules.
  4. If applicable, click on the Edit Rule option.
  5. In the opened window, go to the Caching Settings section.
  6. Set the Cache Operation Level to Cache Based on QueryString+Cookie.
  7. Choose your desired Cache-Control settings (e.g., max-age=3600, public, etc.) and apply them.

After completing these steps, VergeCloud will manage the caching of your content based on the directives you have set, optimizing both performance and content freshness.


    • Related Articles

    • Understanding the Set-Cookie Header

      Understanding the Set-Cookie Header and Caching Behavior The Set-Cookie HTTP response header is used by servers to store cookies on the user's browser. These cookies enable stateful sessions, user personalization, and authentication workflows. ...
    • VergeCloud’s X-Cache and X-Time Headers Explained

      Once VergeCloud's CDN service is activated, the system includes the x-cache and x-time headers in the responses to user requests. What Does X-Cache Mean? The x-cache header can have several possible values: MISS, HIT, and BYPASS. MISS: The requested ...
    • What is the Host header?

      Understanding the Host Header The Host header is a mandatory HTTP request header that specifies the domain name (and optionally the port) of the target server. It plays a fundamental role in HTTP/1.1, as it tells the server which site or application ...
    • What is the Vary Header?

      Understanding the Vary Header in VergeCloud The Vary header is a critical HTTP header that helps configure content caching based on specific request conditions, such as browser type, encoding support, or user preferences. With VergeCloud's advanced ...
    • Cross-Origin Resource Sharing (CORS)

      Cross-Origin Resource Sharing (CORS) Header Cross-Origin Resource Sharing (CORS) is a critical web security feature that allows servers to specify who can access their resources and how those resources can be accessed. By defining CORS policies, you ...