---
title: Using VCL snippets
summary: null
url: >-
  https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/using-vcl-snippets
---

VCL snippets are short blocks of [VCL logic](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/about-fastly-vcl) you can include directly in your service configuration. They don't require you to create entire [custom VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/about-fastly-vcl) files, though you can [include snippets in custom VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/using-vcl-snippets#including-snippets-in-custom-vcl) when necessary. Our guide [about VCL snippets](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/about-vcl-snippets) provides details about each type of snippet, including their limitations.

## Creating VCL snippets

To create a VCL snippet via the Fastly control panel:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the **VCL snippets** tab.
6. Click **Add snippet**.
7. Using the **Type** controls, select the type of snippet you want to create:
   - Select `Regular` to create a [regular VCL snippet](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/about-vcl-snippets/#regular-vcl-snippets), which will always require your current service version to be activated before changes to it will take effect.
   - Select `Dynamic` to create a [dynamic VCL snippet](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/about-vcl-snippets/#dynamic-vcl-snippets), which will only require your service version to be activated once, at the time of creation. After activation, changes to the contents of the snippet will be applied immediately.
8. In the **Name** field, enter an appropriate name (for example, `Example Snippet`).
9. Using the **Placement** controls, select the location in which the snippet should be placed in your VCL as follows:
   - Select `init` to insert the snippet above all subroutines in your VCL.
   - Select `within subroutine` to insert the snippet within a specific [subroutine](https://www.fastly.com/documentation/reference/vcl/request-lifecycle) and then select the specific subroutine from the **Select subroutine** menu.
   - Select `none (advanced)` to insert it [manually](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/using-vcl-snippets#manually-including-snippets-in-custom-vcl) in custom VCL.
10. _(Optional)_ In the **Priority** field, enter the order in which you want the snippet to execute. Lower numbers execute first.
11. In the VCL editor area, enter the snippet of VCL logic to be inserted for your service version.
12. Click **Add** to create the snippet.

## Viewing snippets and their code

To view the snippets associated with a service:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the **VCL snippets** tab. The VCL snippets associated with your service appear on the left side of the tab.

The VCL snippets page includes a list of all snippets included in the VCL used by your service. They appear on the left side of the VCL snippets tab and are grouped by the [VCL subroutine](https://www.fastly.com/documentation/reference/vcl/subroutines/) in which they appear and sorted by priority. A number appears next to the subroutine name indicating how many snippets exist within it.

To find a snippet when you have a long list of them associated with your service, consider the following:

- Shorten the snippet list by clicking the carat (`^`) to the right of each subroutine group name.
- Search for a specific snippet by clicking the search icon immediately above the list of snippets and then typing the snippet name in the search box that appears.

To view the code associated with a snippet once you've found it, click the snippet name and the code will appear to the right of the name.

## Viewing a snippet in generated VCL

To view a specific snippet as it appears in generated VCL using the Fastly control panel:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the **VCL snippets** tab.
6. Find the snippet you want in the list of snippets in the left column, click the name of the snippet you want to view.
7. Click the three dots <span class="inline-icons"><img src="/img/icons/more.png" alt="More icon" /></span> to the right of the name of the snippet that you want to view and then select **Show in generated VCL**. The complete VCL for your service appears with that snippet highlighted.

> **HINT:** Generated VCL is not editable. To edit the VCL snippet, refer to the section on [editing VCL snippets](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/vcl-snippets/using-vcl-snippets#editing-vcl-snippets).

## Editing VCL snippets

To edit a snippet via the Fastly control panel, follow these steps.

### Regular Snippets

To edit a regular VCL snippet, follow these steps.

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the **VCL snippets** tab.
6. Select the regular VCL snippet you want to edit.
7. Click the pencil <span class="inline-icons"><img src="/img/icons/pencil.png" alt="Pencil icon" /></span> at the top right of the snippet's displayed code. The Edit snippet page appears.
8. Update the snippet's settings or VCL as appropriate.
9. Click **Save** to save your snippet changes.
10. From the **Activate** menu, select **Activate on Production** to activate the changes on your service.

### Dynamic Snippets

### Editing a dynamic snippet's name, placement, or priority

A dynamic VCL snippet's name, placement, or priority settings are considered _versioned_ information. To edit these settings, follow these steps:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the **VCL snippets** tab.
6. Select the dynamic VCL snippet you want to edit.
7. From the **Edit menu** at the top right of the snippet's displayed code, select **Edit name, placement, or priority**. The Edit snippet page appears.
8. Update the settings as appropriate.
9. Click **Save** to save your snippet changes.
10. From the **Activate** menu, select **Activate on Production** to activate the changes on your service.

### Editing a dynamic snippet's VCL code

A dynamic snippet's VCL code is considered _versionless_ information. To edit the code, follow these steps:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3. Click **Service configuration**.
4. Click **VCL**.
5. Click the **VCL snippets** tab.
6. From the list of snippets, select the dynamic VCL snippet you want to edit.
7. From the **Edit menu** at the top right of the snippet's displayed code, select **Edit snippet code**. The Edit dynamic snippet code page appears.
8. In the VCL editor area, make changes to the dynamic snippet code as needed.
9. Click **Save** to immediately update the service with the new snippet code without needing to clone and activate a new service version.

## Manually including snippets in custom VCL

Snippets will not be rendered in VCL if you select `none (advanced)` for the snippet type in the Fastly control panel or specify a location of `none` for the `type` parameter in the API. This allows you to manually include snippets in custom VCL using the following syntax:

`include "snippet::<snippet name>"`

The same VCL Snippet can be included in custom VCL in as many places as needed. Check out our guide to [working with custom VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/working-with-custom-vcl) for additional details.

## Deleting a VCL snippet

To delete a snippet via the Fastly control panel:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4. Click **VCL**.
5. Click the three dots <span class="inline-icons"><img src="/img/icons/more.png" alt="More icon" /></span> to the right of the name of the snippet that you want to delete and then select **Delete**. A confirmation window appears.
6. Click **Delete**.

## Related content

- [Using VCL](https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/about-fastly-vcl/)
- [VCL snippets API documentation](https://www.fastly.com/documentation/reference/api/vcl-services/snippet/)
- [Regular expressions in Fastly VCL](https://www.fastly.com/documentation/reference/vcl/regex/)
