rack-unscripted

Added by daphonz at May 18, 2011 11:43 Star_smallStar_smallStar_smallStar_small_grayStar_small_gray javascript
GitHub stats:
Magnifier watcher(s)
Arrow_branch fork(s)
Wrench

About

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 if JavaScript is disabled or blocked by that user.

Details

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 by the id, rack-unscripted-no-javascript-warning, so you can style this warning (when it does get displayed) to your heart’s content.

Usage

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"

Sinatra

require 'rack/unscripted' use Rack::Unscripted

blog comments powered by Disqus