Skip to main content
Published in Engineering Insights

Gnarly Learnings from May 2023

Gnarly Learnings from May 2023
Table of contents
  1. Automatic Fetch Request Deduping with Next.js
  2. Variable Fonts in Google Fonts
  3. Active Record's rewhere
  4. Cross-Browser Support for Import Maps
  5. Migration Method: create_join_table
  6. Contributors:

At The Gnar we are always reading, watching, and listening in order to keep our skills sharp and our perspectives fresh. Here are some of the resources we learned from this month.

Automatic Fetch Request Deduping with Next.js#

NextJS focuses a lot on optimization. So it was no surprise to learn about fetch request deduping. When using fetch with Next, any GET requests with the same input will be cached, so that if there are multiple requests for the same resource during a render cycle or between page refreshes, Next will not make the HTTP request again.

Variable Fonts in Google Fonts#

I am always deliberating over which and how many font weights and variants to import from Google Fonts. I want them all, but am I willing to accept the file size overhead? Luckily Google has come up with a significant improvement to web fonts: variable fonts. These fonts allow for a single font to be selected, and that font can be adjusted by weight, slant, and more. Read more about variable fonts.

Active Record's rewhere#

It now takes two hands to count the number of years I have been working with Ruby on Rails and I still regularly discover new concepts and methods. This month, it was rewhere, an Active Record method that allows you to change a previously set where condition for an attribute. If you're thinking "Hey…that sounds an awful lot like the behavior of unscope" you'd be right! That's because it is a shorthand for unscope(where: conditions.keys).where(conditions).

Cross-Browser Support for Import Maps#

A modern choice for including and reusing JavaScript code in web apps is ES modules. There are a variety of ways to implement ES modules but import maps have been gaining popularity in recent years. Popularity, in this case, equates to industry adoption. For example, Rails 7 (released in 2021) allowed us to break away from the Node.js and webpack bundling strategy and leverage import maps instead. Now, import maps are compatible across the three major browser engines which will make developing with them much easier.

Migration Method: create_join_table #

I was late to this party! When creating a join table in Rails, there's no need to pass id: false to a typical table creation method. Instead, just reach for create_join_table.

Contributors:#

Learn more about how The Gnar builds software.

Frequently asked questions

What is rewhere shorthand for?

It is shorthand for unscope(where: conditions.keys).where(conditions). It changes a previously set where condition for an attribute.

What changed for import maps?

The post reports compatibility across the three major browser engines. It also notes that Rails 7 allowed developers to use import maps instead of the Node.js and webpack bundling approach.

Which Rails method creates a join table?

Use create_join_table. The post says this avoids passing id: false to a typical table creation method.

Stay In The Loop

Never miss an update. Get the latest blogs, webinars, and expert insights straight to your inbox from The Gnar.