Frontend: Serving Assets
Pakyow provides an asset pipeline for managing all of the your project's assets, including stylesheets, scripts, images, and fonts. It replaces complex build pipelines and toolchains with a natural approach to organizing and using assets.
Assets that are part of the managed pipeline live in the
frontend/assets folder. The one exception to this is assets that are composed with view templates. You can read more about composed assets in this guide.
How you organize your assets within the assets folder is up to you. Generated applications include a default structure with folders for your images, stylesheets, and scripts. But do what works for you!
Making asset requests
Pakyow exposes your assets the same way they are defined in the
frontend/assets folder, making asset paths fairly predictable. If you're using default configuration values, the assets folder is mounted at the
/assets request path. This means that an image named
logo.png placed in the images folder is served at
Referencing assets in a view template
You can use assets in your view templates just as you would normally:
Note that the
/assets prefix is left off from asset references in the view template. This keeps you from having to update asset references if you decide to serve assets from a different endpoint. Pakyow automatically updates asset references to the final paths when it renders the view. You'll see more of this behavior later when we talk about fingerprinting assets in production.
Creating unmanaged assets
From time to time you may need to include an asset in your application that you don't want managed in the asset pipeline. A good example is the
robots.txt file. Bots expect to find this file at the root level of your website. If you include it in the asset pipeline it will be served at the wrong location (
/assets/robots.txt). It will also be fingerprinted in production, giving it an unpredictable public path.
You can define an unmanaged asset by add the asset file directly to the
public folder in your project. Files in the
public folder will be served alongside other assets, but they won't be fingerprinted or served with cache headers since they aren't part of the managed asset pipeline.