<commit_before>---
title: Static Assets
---

Besides dynamically generated content,
most websites also load other files which are static,
such as images, JavaScript and stylesheets.
These files need not be dynamically generated upon requests.
We call them "static assets" and Skygear provides two ways
to serve these static assets.

1. Simple approach: using the `public_html` directory in your cloud code.
2. More customized approach: using the `static_assets` decorator to
   have a function specifying the locations of the static assets.

## Put your static assets in a directory

The simplest way to serve static assets to your users is to put them into
a directory called `public_html` in your cloud code directory. The static
assets you put in this folder will be automatically available at
`http://<endpoint>/static/`.

For example, if your cloud code project contains a file saved at
`./public_html/images/hero.png`, your user will be able to access it
at `http://<endpoint>/static/images/hero.png`.

## Declare your static assets using decorator

If your cloud code project is more complex,
or if you cannot put your static assets in the `public_html` directory,
you can also declare your static assets using the `static_assets`
decorator so that Skygear knows where to find your static assets.

```python
import skygear
from skygear.utils.assets import directory_assets


@skygear.static_assets('/hello-world')
def set_hello_world_assets():<commit_msg>Fix static asset decorator argument<commit_after>---
title: Static Assets
---

Besides dynamically generated content,
most websites also load other files which are static,
such as images, JavaScript and stylesheets.
These files need not be dynamically generated upon requests.
We call them "static assets" and Skygear provides two ways
to serve these static assets.

1. Simple approach: using the `public_html` directory in your cloud code.
2. More customized approach: using the `static_assets` decorator to
   have a function specifying the locations of the static assets.

## Put your static assets in a directory

The simplest way to serve static assets to your users is to put them into
a directory called `public_html` in your cloud code directory. The static
assets you put in this folder will be automatically available at
`http://<endpoint>/static/`.

For example, if your cloud code project contains a file saved at
`./public_html/images/hero.png`, your user will be able to access it
at `http://<endpoint>/static/images/hero.png`.

## Declare your static assets using decorator

If your cloud code project is more complex,
or if you cannot put your static assets in the `public_html` directory,
you can also declare your static assets using the `static_assets`
decorator so that Skygear knows where to find your static assets.

```python
import skygear
from skygear.utils.assets import directory_assets


@skygear.static_assets('hello-world')
def set_hello_world_assets():
{'fraction_non_alphanumeric': 0.060101867572156194, 'fraction_numerical': 0.0013582342954159593, 'mean_word_length': 4.75390625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029730', 'n_tokens_mistral': 756, 'n_tokens_neox': 733, 'n_words': 409}