Here are the quick steps on how to use ASPAX with an Express.js application:
1. Create a folder structure similar to this one for your project:
Notice: put all your asset sources in /client; don’t put anything in /server/public, as it will be overwritten!
2. Create /client/aspax.yml describing your assets configuration:
3. Install ASPAX globally if you haven’t already, install aspax-express in your application, and also make sure to install any necessary source handling plugins:
4. Add require('aspax-express')(app, path.join(__dirname, 'aspax.json'))before handling views in your main application script (usually /server/app.js):
5. Replace the URLs in your views with asset() function calls, like this:
6. In /server folder you can run any of these:
7. Run your application in either development or production mode:
Notice: if you’re using nodemon in development mode, add aspax.json to .nodemonignore to avoid restarting the application whenever an asset is rebuilt.
1. To improve performance and responsiveness even more, consider using a specialized static assets module such as st instead of express.static. Besides server-side caching and gzip compression, since v0.4.1 st is able to leverage client-side browser caching by correctly setting the appropriate Cache-Control header. See this commit for more info.
2. You can avoid using the additional aspax-express module by implementing your own logic to “adjust” the asset file names in production.