Introduction
I wanted to add an RSS feed to this blog but decided that instead of installing a dependency I’ll build one myself! Here’s how you can set one up in a Phoenix application:
First let’s define a new route in lib/your_app_web/router.ex:
scope "/", YourAppWeb do
...
get "/rss", RSSController, :index
end
Introduction
If you come from a Ruby on Rails background you might be used to having view helpers such as number_with_delimiter up your sleeve and ready to use in any view.
Here’s how to configure functions that are accessible in your Phoenix views:
1) Create a helper module
I usually create a helpers directory under the app_name_web directory. Next create a new module, let’s call it application_helper.ex:
The issue
The other day I ran my blog through GTmetrix website speed test and realised that I had turned on GZIP compression for static assets, but not for dynamic content. This is easily fixed however with 2 lines of code:
Enabling GZIP compression for static assets
To enable compression for static assets add gzip: true (or gzip: Mix.env == :prod for production only) to the Plug.Static config in lib/your_app_web/endpoint.ex: