Building an RSS Feed with Phoenix

Posted by Daniel Wachtel in Phoenix, last updated on 10 October, 2020

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:

Creating the RSS view

First let’s define a new route in lib/your_app_web/router.ex:

scope "/", YourAppWeb do
  ...

  get "/rss", RSSController, :index
end

Read more

Adding Global View Helpers to a Phoenix Application

Posted by Daniel Wachtel in Phoenix, last updated on 06 September, 2020

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:

Read more

Enabling GZIP Compression on a Phoenix Application

Posted by Daniel Wachtel in Phoenix, last updated on 27 August, 2020

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:

Read more