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 application.
  2. Click the configure tab to access the control panel.

    the configure tab

  3. Select the appropriate service from the Service menu.

  4. Click the blue Configure button to the right of the service name.

  5. Click the Content section.

  6. In the Headers area, click the New button to create a new header. The New Header window appears.

    the New Header window

  7. Fill out the New Header window as follows:

    • In the Name field, type an appropriate name, such as Add Content Type.
    • From the Type/Action menus, select Cache and Set.
    • In the Destination field type http.Content-Type.
    • In the Source field type the content type you want match, such as "application/javascript; charset=utf-8".
    • From the Ignore if Set menu, select No.
    • In the Priority field, type 10.
  8. Click the Create button. A new header appears in the Headers area of the Content section.

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

  1. Click the gear icon to the right of the new header name and select Cache Conditions from the menu. The Choose Condition window appears.
  2. In the Options section, click the New button to add a new condition. The New Condition window appears.
  3. Fill out the next New Condition window as follows:
    • 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 our request for files ending in .js).
  4. Click Create to create the new condition.
  5. Deploy your configuration changes.
Back to Top