
Security Fundamentals
Turtles, Clams, and Cyber Threat Actors: Shell Usage
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
rails_critical_css_server
Advanced tools
If you've run Google Pagespeed Insights on your web app, you might have seen this message:
Eliminate render-blocking JavaScript and CSS in above-the-fold content
Your page has blocking CSS resources. This causes a delay in rendering your page. None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.
This is a Ruby on Rails client for Critical CSS Server, designed to solve this problem for you outside of your build process.
Add this line to your application's Gemfile:
gem 'rails_critical_css_server'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_critical_css_server
In your application layout, just wrap your CSS in a call to Rewrite
:
<%= RailsCriticalCssServer::Rewrite.call self do %>
<%= stylesheet_link_tag "application" %>
<% end %>
Every time a new controller action is rendered, the server will begin to compile the bare-minimum CSS required to render the above the fold content on that page. Eventually, once the CSS is available, the critical portion will be injected, and the remainder of your CSS will be lazy-loaded with JavaScript.
The header will be rendered normally:
<link rel="stylesheet" href="/assets/application.css" />
<style>/* inline css rules injected here... */</style>
<script>// loadCSS injected here...</script>
<script>loadCSS("/assets/application.css");</script>
<noscript>
<link rel="stylesheet" href="/assets/application.css" />
</noscript>
Each time CSS is compile, it is cached using the cache key: [controller, action, version]
.
By default, we used Heroku's environment variable HEROKU_RELEASE_VERSION
to bust the version cache. This is available
through the Heroku Labs: Dyno Metadata.
If this doesn't work for you, set the version
flag in config to some other deploy-unique id, so that new CSS can be
generated for you each time you change your pages.
In config/initializers/critical_css_server.rb
:
RailsCriticalCssServer.config do |c|
c.host = ENV['CRITICAL_CSS_SERVER_URL'] # URL of Critical CSS Server
c.auth_token = ENV['CRITICAL_CSS_SERVER_AUTH_TOKEN'] # Credentials for Critical CSS Server
c.timeout = 0.05 # Timeout when requested critical CSS in layout.
c.version = ENV['HEROKU_RELEASE_VERSION'] # Unique id for the current deploy. Used to bust the cache after changes are made
c.width = 900 # width of viewport to optimize CSS for
c.height = 1200 # height of viewport to optimize CSS for
c.force_selectors = [] # force individual selectors to be included, even if they are not rendered on the first pass. Useful for JavaScript-enabled styles.
end
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that rails_critical_css_server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
Security News
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
Product
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.