Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Middleware for adding a warning to a page for users who do not have JavaScript enabled.

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rack-unscripted.gemspec


This is a small piece of Rack middleware that will append a message to your HTML warning a user that they need to enable JavaScript in order to properly view your site.

The Rack middleware will append a <div> right after the opening body tag, but hide it via a CSS directive that is written by JavaScript in the <head> section. This prevents any flashing that can happen by merely hiding the element via JS directly. We don't use the <noscript> tag since it has spotty support and doesn't work when a user is using a browser plugin to whitelist JS on certain sites.

The div that is created can be referenced in CSS the the id, rack-unscripted-no-javascript-warning, so you can style this warning (when it does get displayed) to your heart's content.


Original HTML:

    <title>The Bucket of Truth</title>

HTML with Rack::Unscripted enabled:

    <title>The Bucket of Truth</title>
    <script type="text/javascript">
      document.write('<style>#rack-unscripted-no-javascript-warning { display:none }</style>');
    <div id='rack-unscripted-no-javascript-warning'>
      Warning, this site requires JavaScript to function properly. Please enable it.


Make sure to install this gem:

gem install rack-unscripted

or, add the following to your Gemfile:

gem 'rack-unscripted'

Then you need to configure your middleware stack to use this library.


use Rack::Unscripted


use Rack::Unscripted, "Custom warning message to users without JavaScript enabled."

Example Configuration

Rails 3.x

In config/initializers/rack_unscripted.rb

MyApplicationName::Application.config.middleware use "Rack::Unscripted"

Rails 2.3.x

In config/environment.rb

config.middleware.use "Rack::Unscripted"


require 'rack/unscripted'
use Rack::Unscripted
Something went wrong with that request. Please try again.