HTTP Caching Essentials: Concepts, Headers, and Strategies Quiz

Explore crucial concepts of HTTP caching, including key headers, cache types, validation, and common pitfalls. This quiz helps you assess your knowledge of optimizing web performance, understanding caching strategies, and avoiding costly caching mistakes for fast and reliable sites.

  1. Purpose of HTTP Caching

    What is the primary goal of HTTP caching in the context of web performance?

    1. To reduce unnecessary work by limiting repeated data transfers
    2. To increase server processing for each user request
    3. To ensure all data is always freshly generated from the backend
    4. To make websites display advertisements more quickly

    Explanation: HTTP caching aims to avoid redundant data transfers between clients and servers, saving bandwidth and speeding up page loads. Increasing server work is the opposite of caching’s purpose. Generating fresh backend data for every request is inefficient and ignores cache benefits. While speed helps all website operations, displaying advertisements more quickly is not the intended core function of HTTP caching.

  2. Cache-Control: no-cache Directive

    When the Cache-Control header is set to 'no-cache', which behavior is expected from caches?

    1. Cached resource can be reused without validation
    2. Resource must be revalidated with the origin server before use
    3. Resource cannot be stored in the cache at all
    4. Only static resources like images are cached

    Explanation: With 'no-cache', caches can store the resource but must check with the server for validation before reusing the resource. 'No-cache' does not mean that nothing is cached, which is a common misconception. The 'no-store' directive, not 'no-cache', prevents any storage in caches. Limiting caching to static resources is an unrelated policy.

  3. Distinguishing 'public' and 'private' Cache-Control

    Which scenario best fits the use of the 'private' directive in the Cache-Control header?

    1. Caching a user’s personal dashboard displaying their account data
    2. Serving a global CSS file for all users
    3. Caching publicly accessible images on a CDN
    4. Storing generic product listings

    Explanation: 'Private' is used for content specific to a single user, such as personalized dashboards, to ensure shared caches don’t serve confidential information to other users. Global CSS files and images are general resources suitable for 'public' caching. Product listings, unless user-specific, also do not require 'private' caching.

  4. Understanding the Expires Header

    What does the 'Expires' header specify in an HTTP response?

    1. How many times a browser can request the resource
    2. The absolute date and time after which the resource is considered stale
    3. A relative duration in seconds for cache validity
    4. The server's timezone configuration

    Explanation: The 'Expires' header provides a fixed timestamp indicating when cached content should be considered stale. It does not limit request counts, determine durations in seconds (for that, use 'Cache-Control: max-age'), or reference server timezone settings. Its value is a specific date-time string.

  5. Impact of the Age Header

    If an HTTP response contains an 'Age' header with a value of 180, what does this indicate?

    1. The resource was fetched from the origin 180 seconds ago
    2. The client waited 180 milliseconds for a response
    3. The cache will expire in exactly 180 more seconds
    4. Only proxies are allowed to cache the resource

    Explanation: The 'Age' header records how many seconds have passed since the resource was retrieved from its origin, reflecting how long it’s been cached. Response-time in milliseconds is unrelated. 'Age' does not predict future expiration and has no bearing on caching permissions for proxies.

  6. Function of ETag Header

    What is the primary role of an ETag header in HTTP caching mechanisms?

    1. To indicate the expiration date of a cached resource
    2. To uniquely identify a specific version of a resource for validation
    3. To provide an access control token for private content
    4. To instruct proxies to ignore cache rules

    Explanation: The ETag header assigns a unique identifier to a resource version, letting servers efficiently check if cached content matches the current version. It does not stipulate expiration (see 'Expires'), isn’t meant for access control, and does not override proxy behavior.

  7. Browser vs. Proxy Caches

    Which statement accurately describes the difference between browser and proxy caching?

    1. Browser caches only serve a single user, while proxy caches can serve multiple users
    2. Proxy caches are always located within the user’s browser
    3. Browser caches are more secure for sensitive shared resources
    4. Proxy caches never validate content with the origin server

    Explanation: Browser caches are private to each user's device, storing items that should not be shared across users. Proxy caches, such as those in CDNs or ISPs, can serve cached resources to multiple users. Proxy caches are not located within browsers, security depends on cache settings, and both cache types may perform validations as necessary.

  8. Interpreting max-age=0

    If a resource includes 'Cache-Control: max-age=0' in its response header, what is the cache's expected behavior?

    1. Cache can use the resource for any length of time
    2. Cache should immediately treat the resource as stale and revalidate on each request
    3. The resource cannot be cached at all
    4. The resource remains fresh for exactly one hour

    Explanation: 'max-age=0' signals that the resource is already stale and requires validation every time before reuse. It does not provide indefinite or hour-long freshness, nor does it completely forbid caching, which would require 'no-store'. Revalidation on every access is the intended outcome.

  9. ETag vs Last-Modified

    How do ETag and Last-Modified headers differ in HTTP caching validation?

    1. ETag provides a unique value for each resource version, while Last-Modified records the date and time of last change
    2. Both always provide the same type of validation value
    3. Last-Modified is more precise than ETag for every type of resource
    4. ETag cannot be used for dynamic content

    Explanation: ETag offers fine-grained validation based on resource versions, while Last-Modified uses timestamps to indicate changes. They do not generate identical values, and each has advantages for different scenarios. ETag is effective for dynamic resources, while Last-Modified can be less precise for rapidly updated content.

  10. Caching for Static Assets vs. HTML

    Why should static assets like JavaScript or CSS files typically have longer cache lifetimes than HTML documents?

    1. Static assets change infrequently and can be safely reused, while HTML content may update often
    2. HTML documents are more secure when cached for longer durations
    3. Browsers cannot cache static assets by default
    4. Long cache times for HTML improve SEO rankings directly

    Explanation: Static assets are less likely to change, so longer caching reduces server load and accelerates delivery. HTML documents are often updated with dynamic content, so shorter caching helps avoid serving outdated pages. Longer caching does not increase HTML security or SEO scores in this context, and browsers do cache static assets when allowed.