LOG IN SIGN UP
Documentation

Setting Content Type based on file extension

In some situations you may want to override the content type that a backend returns. To do that you will need to create a new header object and an associated condition.

  1. Log in to the Fastly web interface and click the Configure link.
  2. From the service menu, select the appropriate service.
  3. Click the Edit configuration button and then select Clone active. The service version page appears.
  4. Click the Content tab. The Content page appears.

    the Content page

  5. Click the Create header button. The Create a new header page appears.

    the Create a new header page

  6. Fill out the Create a new header fields as follows:

    • From the Type menu, select Cache, and from the Action menu, select Set.
    • In the Destination field, type http.Content-Type.
    • In the Source field, type the content type you want to match, such as "application/javascript; charset=utf-8".
    • From the Ignore if set menu, select No.
    • In the Priority field, type 10.
    • In the Description field, type an appropriate name (e.g.,Add Content Type).
  7. Click the Create button.

Once you have created the header object, apply a condition. Otherwise, that particular object is applied to all requests.

  1. Click the Attach a condition link to the right of the new header name. The Create a new cache condition window appears.

    setting Content type

  2. Fill out the Create a new cache condition fields as follows:

    • Leave the Type menu set to Cache.
    • In the Name field, type a descriptive name, such as Files ending with .js.
    • In the Apply if field, type the condition that matches your request, such as req.url.ext == "js" (to match the request for files ending in .js).
  3. Click the Save and apply to button to create the new condition.

  4. Click the Activate button to deploy your configuration changes.


Back to Top