Using Static Assets on Pages

Last updated on June 26, 2024.

This guide discusses how you can use static assets (e.g. CSS, Javascript, or HTML files) on your pages.

Important

This document discusses using static assets on your page at the code level. You can perform the same action intuitively with the help of the Insites Admin. Please visit our Assets documentation to learn more.

Prerequisites

To follow the steps in this tutorial, review the required directory structure for your codebase, and understand the concepts of pages, layouts, and assets. You are extending code samples from the previous tutorials on this documentation:

Steps

Note

The steps described in this article use Liquid filters. Please visit our documentation on Liquid filters to learn more.

Using static assets on your pages is a four-step process:

  • Step 1: Creating an 'assets' directory and subdirectories
  • Step 2: Creating or adding assets
  • Step 3: Checking assets
  • Step 4: Accessing assets

Step 1: Creating an 'assets' directory and subdirectories

If you are starting from scratch (without creating the codebase), create an directory inside .

If you have already created the codebase, you can skip this step and proceed to locate your directory.

Create subdirectories for different assets inside the directory: for this tutorial, create for storing Javascript files and for storing CSS files.

Step 2: Creating or adding assets

Create a couple of assets.

Create a CSS file in the directory:

Create a Javascript file in the directory:

Create an HTML file in the directory:

Step 3: Checking assets

Use variable to check your assets. This will list the full URL of your assets on our content delivery network, including the time of the latest update (used for caching).

Step 4: Accessing assets

To access assets, use the filter in your liquid file, e.g. layout:

Sync or deploy. The background colour of the page has changed to the colour specified in the file, and the link to works. If you check the developer console, the Javascript is there.

Note

If you are syncing, you are only adding and changing files, and they will stay in the database even if you delete them on your computer as long as you do not deploy.

Next Steps

Congratulations! You have learned how to use static assets on your pages. Now you can learn about adding visuals to your pages using CSS or Javascript.

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.