Git Product home page Git Product logo

rack-offline's Introduction

HTML5 Offline

HTML5 provides two robust offline capabilities already implemented in popular mobile devices, such as the iPhone and Android, and on modern desktop browsers based on the Webkit and Gecko rendering engines.

Usage

The easiest way to use Rack::Offline is by using Rails::Offline in a Rails application.
In your router:

match "/application.manifest" => Rails::Offline

This will automatically cache all JavaScript, CSS, and HTML in your public
directory, and will cause the cache to be updated each request in development
mode.

You can fine-tune the behavior of Rack::Offline by using it directly:

offline = Rack::Offline.configure do
  cache "images/masthead.png"

  public_path = Rails.public_path
  Dir[public_path.join("javascripts/*.js")].each do |file|
    cache file.relative_path_from(public_path)
  end

  network "/"
end

And when used with Rails asset pipeline:

  if Rails.env.production?
    offline = Rack::Offline.configure :cache_interval => 120 do      
      cache ActionController::Base.helpers.asset_path("application.css")
      cache ActionController::Base.helpers.asset_path("application.js")
      # cache other assets
      network "/"  
    end
    match "/application.manifest" => offline  
  end

You can pass an options Hash into #configure in Rack::Offline:

name purpose value in Rails::Offline
:cache false means that the browser should download the assets on each request if a connection to the server can be made the same as config.cache_classes
:logger a logger to send messages to Rails.logger
:root The location of files listed in the manifest Rails.public_path

Application Cache

The App Cache allows you to specify that the browser should cache certain files, and ensure that the user can access them even if the device is offline.

You specify an application’s cache with a new manifest attribute on the html element, which must point at a location on the web that serves the manifest. A manifest looks something like this:

CACHE MANIFEST

javascripts/application.js
javascripts/jquery.js
images/masthead.png

NETWORK:
/

This specifies that the browser should cache the three files immediately following CACHE MANIFEST, and require a network connection for all other URLs.

Unlike HTTP caches, the browser treats the files listed in the manifest as an atomic unit: either it can serve all of them out of the manifest or it needs to update all of them. It will not flush the cache unless the user specifically asks the browser to clear the cache or for security reasons.

Additionally, the HTML file that supplies the manifest attribute is implicitly in the manifest. This means that the browser can load the HTML file and all its cached assets as a unit, even if the device is offline.

In short, the App Cache is a much stickier, atomic cache. After storing an App Cache, the browser takes the following (simplified) steps in subsequent requests:

  1. Immediately serve the HTML file and its assets from the App Cache. This happens
    whether or not the device is online
  2. If the device is offline, treat any resources not specified in the App Cache
    as 404s. This means that images will appear broken, for instance, unless you
    make sure to include them in the App Cache.
  3. Asynchronously try to download the file specified in the manifest attribute
  4. If it successfully downloads the file, compare the manifest byte-for-byte with
    the stored manifest.
    • If it is identical, do nothing.
    • If it is not identical, download (again, asynchronously), all assets specified
      in the manifest
  5. Along the way, fire a number of JavaScript events. For instance, if the browser
    updates the cache, fire an updateready event. You can use this event to
    display a notice to the user that the version of the HTML they are using is
    out of date

App Cache Considerations

The first browser hit after you change the HTML will always serve up stale HTML
and JavaScript. You can mitigate this in two obvious ways:

  1. Treat your mobile web app as an API consumer and make sure that your app
    can support a “client” that’s one version older than the current version
    of the API.
  2. Force the user to reload the HTML to see newer data. You can detect this
    situation by listening for the updateready event

A good recommendation is to have your server support clients at most one
version old, but force older clients to reload the page to get newer data.

Regular users of your application will receive updates through normal usage,
and will never be forced to update. Irregular users may be forced to update
if they pick up the application months after they last used in. In all, a
pretty good trade-off.

While this may seem cumbersome at first, it makes it possible for your users
to browse around your application more naturally when they have flaky
connections, because the process of updating assets (including HTML)
always happens in the background.

Updating the App Cache

You will need to make sure that you update the cache manifest when any of
the underlying assets change.

Rack::Offline handles this using two strategies:

  1. In development, it generates a SHA hash based on the timestamp for each
    request. This means that the browser will always interpret the cache
    manifest as stale. Note that, as discussed in the previous section,
    you will need to reload the page twice to get updated assets.
  2. In production, it generates a SHA hash once based on the contents of
    all the assets in the manifest. This means that the cache manifest will
    not be considered stale unless the underlying assets change.

Rails::Offline caches all JavaScript, CSS, images and HTML
files in public and uses config.cache_classes to determine which of
the above modes to use. In Rails, you can get more fine-grained control
over the process by using Rack::Offline directly.

Local Storage

Browsers that support the App Cache also support Local Storage, from the
HTML5 Web Storage Spec. IE8 and above also support Local
Storage.

Local Storage is a JavaScript API to an extremely simple key-value store.

It works the same as accessing an Object in JavaScript, but persists the
value across sessions.

localStorage.title = "Welcome!"
localStorage.title //=> "Welcome!"

delete localStorage.title
localStorage.title //=> undefined

Browsers can offer different amounts of storage using this API. The
iPhone, for instance, offers 5MB of storage, after which it asks the
user for permission to store an additional 10MB.

You can reclaim storage from a key by deleteing it or
by overwriting its value. You can also enumerate over all keys in
the localStorage using the normal JavaScript for/in
API.

In combination with the App Cache, you can use Local Storge to store
data on the device, making it possible to show stale data to your
users even if no connection is available (or in flaky connection
scenarios).

Basic JavaScript Strategy

You can implement a simple offline application using only a few
lines of JavaScript. For simplicity, I will use jQuery, but you
can easily implement this in pure JavaScript as well. The
example is heavily commented, but the total number of lines of
actual JavaScript is quite small.

jQuery(function($) {
  // Declare a function that can take a JS object and
  // populate our HTML. Because we used the App Cache
  // the HTML will be present regardless of online status
  var updateArticles = function(object) {
    template = $("#articles")
    localStorage.articles = JSON.stringify(object);
    $("#article-list").html(template.render(object));
  }

  // Create a flag so we don't poll the server twice
  // at once
  var updating = false;

  // Create a function that will ask the server for
  // updates to the article list
  var remoteUpdate = function() {
    // Don't ping the server again if we're in the
    // process of updating
    if(updating) return;

    updating = true;

    $("#loading").show();
    $.getJSON("/article_list.json", function(json) {
      updateArticles(json);
      $("#loading").hide();
      updating = false;
    });
  }

  // If we have "articles" in the localStorage object,
  // update the HTML with the stale articles. Even if
  // the user never gets online, they will at least
  // see the stale content
  if(localStorage.articles) updateArticles(JSON.parse(localStorage.articles));

  // If the user was offline, and goes online, ask
  // the server for updates
  $(window).bind("online", remoteUpdate);

  // If the user is online, ask for updates now
  if(window.navigator.onLine) remoteUpdate();
})

rack-offline's People

Contributors

arsduo avatar blaines avatar dohmoose avatar dsrw avatar jahan-paisley avatar jimmy avatar maccman avatar tchak avatar twinge avatar wycats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rack-offline's Issues

Setting up config.ru for use on Heroku

I have deployed a static site using https://devcenter.heroku.com/articles/static-sites-ruby

Does anyone know how to set up the config.ru for use of rack-offline on Heroku?

I have tried use Rack::Offline, :cache => "images", :root => "public" , but it complains of wrong number of arguments.

Remove console logs for application cache event?

Hi,

Application Cache Progress event (59 of 72) http://lvh.me:3000/images/icon-day-view.png  diary_app:1 

Application Cache Progress event (60 of 72) http://lvh.me:3000/images/embed/tab-month.png diary_app:1 

Application Cache Progress event (61 of 72) http://lvh.me:3000/images/embed/homework-progress.png diary_app:1 

Application Cache Progress event (62 of 72) http://lvh.me:3000/images/embed/row-header-border-left.png diary_app:1 

Application Cache Progress event (63 of 72) http://lvh.me:3000/images/top-nav-right-btn-2.png

Is there a way to remove the console log messages that are being shown up during the Cache process?

Update 1:

Tried changing the log_level, but no change yet.

Using this with S3 Storage

I use S3/Cloudfront to store my assets, how would I make it so that Rack offline uses S3 to pull assets for caching?

undefined method `public', Rails 3.2.3 & 3.2.1

I've followed the instructions on the readme and the RailsCast (http://railscasts.com/episodes/247-offline-apps-part-1) on Rails on both Rails 3.2.3 and 3.2.1 but I get the same error when I request /application.manifest. What does this mean?

undefined method `public' for #Rails::Paths::Root:0x007faa726fde88

Here's the full trace

rack-offline (0.6.2) lib/rack-offline.rb:12:in initialize' rack-offline (0.6.2) lib/rack-offline.rb:6:innew'
rack-offline (0.6.2) lib/rack-offline.rb:6:in call' journey (1.0.3) lib/journey/router.rb:68:inblock in call'
journey (1.0.3) lib/journey/router.rb:56:in each' journey (1.0.3) lib/journey/router.rb:56:incall'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in call' sass (3.1.19) lib/sass/plugin/rack.rb:54:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in call' rack (1.4.1) lib/rack/etag.rb:23:incall'
rack (1.4.1) lib/rack/conditionalget.rb:25:in call' actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in call' actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:incall'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in context' rack (1.4.1) lib/rack/session/abstract/id.rb:200:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in call' activerecord (3.2.3) lib/active_record/query_cache.rb:64:incall'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in call' actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in _run__619295624823630679__call__1725191931782040833__callbacks' activesupport (3.2.3) lib/active_support/callbacks.rb:405:in__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in _run_call_callbacks' activesupport (3.2.3) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in call' actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in call' railties (3.2.3) lib/rails/rack/logger.rb:26:incall_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in call' actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:incall'
rack (1.4.1) lib/rack/methodoverride.rb:21:in call' rack (1.4.1) lib/rack/runtime.rb:17:incall'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.4.1) lib/rack/lock.rb:15:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in call' railties (3.2.3) lib/rails/engine.rb:479:incall'
railties (3.2.3) lib/rails/application.rb:220:in call' rack (1.4.1) lib/rack/content_length.rb:14:incall'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in call' rack (1.4.1) lib/rack/handler/webrick.rb:59:inservice'
/Users/matharden/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/webrick/httpserver.rb:111:in service' /Users/matharden/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/webrick/httpserver.rb:70:inrun'
/Users/matharden/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Installation Instructions

Looking for simple installation instructions in order to get this to work as either a gem or a plugin.

When I follow instructions for installing general rack based gems I get some esoteric errors and can't get this to work.

I know this is a user issue and is definately PEBKAC.

example on github page don't work

Hi there,

I found out that the example that was posted does not work (at least nog in 1.8.6 @ rails3).

I am reffering to this bit:

offline = Rack::Offline.configure do
  cache "images/masthead.png"

  public_path = Rails.public_path
  Dir[public_path.join("javascripts/*.js")].each do |file|
    cache file.relative_path_from(public_path)
  end

  network "/"
end

This gives two errors:
#1 .join does not work on a string.
#2 .relative_path_name is a method not known to string either

Here is a fixed version:

offline = Rack::Offline.configure do
  cache "images/masthead.png"

  public_path = Rails.public_path
  Dir[public_path + "javascripts/*.js")].each do |file|
    cache file.gsub(public_path, "") #anyone know a better one? Without gsub?
  end

  network "/"
end

Dynamic content + cached mode

It's possible to add dynamic content to the manifest, for example:

offline = Rails::Offline.configure do
  cache "/pages/1/"
end

However, :cache => true trips over this because it expects that path to exist as a file so that it can hash the contents. I'm not entirely sure what the right solution for this is...

  • Discourage people from using cached mode with dynamic content, since their browser ought to check it for updates.
  • Skip hashing of anything that doesn't exist as a file, let the developer worry about forcing those updates.
  • Allow the developer to provide an alternative cache "key" somewhere - either hardcoded or dynamically calculated (like pulling an updated_at timestamp).

undefined method 'public'

The manifest isn't working for me so I visited the address it's supposed to live in: "/application.manifest" and this is the error I got:

undefined method `public' for #Rails::Paths::Root:0xb6401b0c

with the following env dump:

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5"
HTTP_ACCEPT_CHARSET: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CACHE_CONTROL: "max-age=0"
HTTP_CONNECTION: "keep-alive"
HTTP_COOKIE: "__utmz=162457789.1273070594.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); user_credentials=9aa5ff19695022d44a1981317cf97e9fd2a2f2dcb145f4dfcc17853aa36474526affec0e2f38364628bc68998ac568bbf54d18ff2e604e43e873154d0a34c46b%3A%3A926; __utma=162457789.513641191.1284324662.1284804676.1284837523.21; __utmc=162457789; __utmb=162457789.1.10.1284837523; _got3ds_session=BAh7ByIQX2NzcmZfdG9rZW4iMXVYNEt2NThKSXV3N3JFaVd6TEs0MTk0T0owU1piKzIrbXBmaGZ2Tkp6eXM9Ig9zZXNzaW9uX2lkIiVkNDJhNTBiYzkzYjlkMTVjYzg3MWQ0YTJjMDMzNjc4YQ%3D%3D--68fc5c92db116b73d28f764e02de416542922649"
HTTP_HOST: "0.0.0.0:3000"
HTTP_USER_AGENT: "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.8 Safari/534.7"
HTTP_VERSION: "HTTP/1.1"
PATH_INFO: "/application.manifest"
QUERY_STRING: ""
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost"
REQUEST_METHOD: "GET"
REQUEST_PATH: "/"
REQUEST_URI: "http://0.0.0.0:3000/application.manifest"
SCRIPT_NAME: ""
SERVER_NAME: "0.0.0.0"
SERVER_PORT: "3000"
SERVER_PROTOCOL: "HTTP/1.1"
SERVER_SOFTWARE: "WEBrick/1.3.1 (Ruby/1.8.7/2010-06-23)"
action_dispatch.parameter_filter: [:password]
action_dispatch.request.content_type: nil
action_dispatch.request.parameters: {}
action_dispatch.request.path_parameters: {}
action_dispatch.request.query_parameters: {}
action_dispatch.request.request_parameters: {}
rack.errors: #IO:0xb7595558
rack.input: #StringIO:0xb64961d0
rack.multiprocess: false
rack.multithread: false
rack.request.cookie_hash: {"user_credentials"=>"9aa5ff19695022d44a1981317cf97e9fd2a2f2dcb145f4dfcc17853aa36474526affec0e2f38364628bc68998ac568bbf54d18ff2e604e43e873154d0a34c46b::926", "__utma"=>"162457789.513641191.1284324662.1284804676.1284837523.21", "__utmb"=>"162457789.1.10.1284837523", "__utmc"=>"162457789", "_got3ds_session"=>"BAh7ByIQX2NzcmZfdG9rZW4iMXVYNEt2NThKSXV3N3JFaVd6TEs0MTk0T0owU1piKzIrbXBmaGZ2Tkp6eXM9Ig9zZXNzaW9uX2lkIiVkNDJhNTBiYzkzYjlkMTVjYzg3MWQ0YTJjMDMzNjc4YQ==--68fc5c92db116b73d28f764e02de416542922649", "__utmz"=>"162457789.1273070594.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"}
rack.request.cookie_string: "__utmz=162457789.1273070594.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); user_credentials=9aa5ff19695022d44a1981317cf97e9fd2a2f2dcb145f4dfcc17853aa36474526affec0e2f38364628bc68998ac568bbf54d18ff2e604e43e873154d0a34c46b%3A%3A926; __utma=162457789.513641191.1284324662.1284804676.1284837523.21; __utmc=162457789; __utmb=162457789.1.10.1284837523; _got3ds_session=BAh7ByIQX2NzcmZfdG9rZW4iMXVYNEt2NThKSXV3N3JFaVd6TEs0MTk0T0owU1piKzIrbXBmaGZ2Tkp6eXM9Ig9zZXNzaW9uX2lkIiVkNDJhNTBiYzkzYjlkMTVjYzg3MWQ0YTJjMDMzNjc4YQ%3D%3D--68fc5c92db116b73d28f764e02de416542922649"
rack.request.query_hash: {}
rack.request.query_string: ""
rack.run_once: false
rack.session: {"_csrf_token"=>"uX4Kv58JIuw7rEiWzLK4194OJ0SZb+2+mpfhfvNJzys=", "session_id"=>"d42a50bc93b9d15cc871d4a2c033678a"}
rack.session.options: {:httponly=>true, :expire_after=>nil, :id=>"d42a50bc93b9d15cc871d4a2c033678a", :path=>"/", :key=>"_session_id", :domain=>nil}
rack.url_scheme: "http"
rack.version: [1, 1]

I don't understand a word of it but I guess it's parsing the "public" folder as a method?

files in configuration not listed in the generated manifest ...

I installed it, configure and run my app... in my dev log I get :

Started GET "/fr/application.manifest" for 127.0.0.1 at 2013-01-25 11:26:40 +0100
CACHE MANIFEST
  # aba331a67ba974bf70c665dfc48a1bea5da7d8fe352c46a76af07f45c339d422
404.html
422.html
500.html
offline.html
NETWORK:
*
Started GET "/fr/404.html" for 127.0.0.1 at 2013-01-25 11:26:40 +0100
Started GET "/fr/422.html" for 127.0.0.1 at 2013-01-25 11:26:40 +0100
Started GET "/fr/500.html" for 127.0.0.1 at 2013-01-25 11:26:40 +0100
Started GET "/fr/offline.html" for 127.0.0.1 at 2013-01-25 11:26:40 +0100
Started GET "/" for 127.0.0.1 at 2013-01-25 11:26:40 +0100

These are all the html files in my public folder ... but why I dont have also the files mentioned in the configuration ?

Rack::Offline.configure do
  cache "images/favicon.ico"
  cache "images/isabelle.png"
  public_path = Pathname.new(Rails.public_path)
  Dir["#{public_path.to_s}/uploads/craftwork/image/**/*.{jpg,png,jpeg}"].each do |file|
    cache Pathname.new(file).relative_path_from(public_path) if File.file?(file)
  end
  network "/fr/contacts.html"
  network "/en/contacts.html"
  network "/fr/informations.html"
  network "/en/information.html"
  fallback "/html/" => "/offline.html"
end

the 4 files in configuration are not listed in the generated manifest .... what's wrong with my config ?

Ruby 1.8.7 - uninitialized constant Rails::Rack::Offline

Just wanted to let you know of an issue I had...
Ruby 1.8.7 threw a "uninitialized constant Rails::Rack::Offline" in lib/rack-offline.rb:4
Apparently this works in ruby 1.9, but I wasn't able to test it myself.

Changing line four to " class Offline < ::Rack::Offline" fixed the issue.

SHA hash seems to be broken

We began experimenting with the Rack-Offline gem to generate appcache files for our Sencha Touch mobile app within the Rails 3.1 asset pipeline. The SHA hash doesn't seem to work correctly, though.

In production mode, the hash stays consistent for a few requests/seconds and then changes. cache_classes is on, so I don't understand why it isn't being kept constant while the file contents are not changing.

I tried using the forked version referenced in #18 but this did not work for me either.

This is what my config in my routes file looks like:

mobile_cache = Rack::Offline.configure do
    cache "assets/mobile/app/dependencies.js"
…

    cache "/mobile-images/logo.gif"
…

    network "/"
  end

  match "/manifest.appcache" => mobile_cache

I also tried setting ":cache => true" as below. This does freeze the SHA but it doesn't change at all, even if the contents of the file changes.

mobile_cache = Rack::Offline.configure(:cache => true) do 
…
end

In development, manifest.appcache can just 404 to completely turn it off.

HTML5 offline gets annoying, and why not just completely turn it off when in development? There should be an option to turn it on, for basic testing, but otherwise it just gets in the way.

This can easily be done by returning a 404 on the request for the appcache.

Note: this is also how you can make an html5 offline app no longer an offline app, and instead like a regular website.

Hash not always updating in dev

Hi there,

When I reload the manifest in my browser (http://localhost:3000/application.manifest, Safari) , I would expect to see the hash change on every reload. It is not. It randomly changes ever 5-10 times or so. Every time I reload, however, Webrick shows this:

Started GET "/application.manifest" for 127.0.0.1 at 2012-01-23 11:57:24 -0800

I am definitely in development mode and am not caching classes. Any ideas? Thanks!

Support for Rails 3.1

I'm kinda stumped: no matter what I do w/ rack-offline, it always produces:

CACHE MANIFEST
# f2d7f204566173c89ce729e46bdd7e8c6d75087f6b2213367c49b598e3d04dc2
404.html
422.html
500.html
index.html

NETWORK:
/

The hash will update, but no files are added to the manifest. So far, I've:

  1. Tried using the 'master' branch to support the new assets folder. Neither placing files there, nor the public folder works.
  2. Tried adding an initializer and passing :cache => true to Rack::Offline.configure.
  3. Tried adding a straight-up cache 'assets/application.js' to an initializer.
  4. Turning off cache-busting in application.rb.

This is in a plain vanilla Rails 3.1.0 app. Does the manifest file not update in development mode? Am I missing something obvious?

GET errors in console when loading cached content with no network connection

Hi - thank you for all of your work.

I'm using rack::offline to cache content for users to access when they don't have an internet connection.

In both development and production, there seems to be an issue with the caching. First, I visit the page, and the cached is updated. When I turn off my network connection in development, the page seems to function ok, but I get the following errors in the console.

GET http://localhost:3000/assets/application.self-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css?body=1 net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/assets/jquery.self-660adc51e0224b731d29f575a6f1ec167ba08ad06ed5deca4f1e8654c135bf4c.js?body=1 net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/assets/jquery_ujs.self-e87806d0cf4489aeb1bb7288016024e8de67fd18db693fe026fe3907581e53cd.js?body=1 net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/assets/application.self-377610cd7c1509e934744c810e3b4cf672dfbcacac3274e7d039827e2ae0fcc7.js?body=1 net::ERR_CONNECTION_REFUSED

In production, I am getting a similar set of errors, although it is only for two files...

Can you explain what these files are, and how I can clear these errors?

Again, many thanks.

Does not work with unicorn, rails 3 and ruby 1.9

When this plugin is used with unicorn and ruby 1.9. It breaks with following error

Read error: #<NoMethodError: undefined method `each' for #<String:0x00000100d88118>>
/Volumes/DATA/Bhavin/.rvm/gems/ruby-1.9.2-p0/gems/unicorn-3.0.0/lib/unicorn/http_response.rb:45:in `http_response_write'

While debugging, line no. 59 rack/offline.rb is breaking the code.

[200, {"Content-Type" => "text/cache-manifest"}, body.join("\n")]

line no. 45 in unicorn/http_response.rb looks like

body.each { |chunk| socket.write(chunk) }

It would have worked in ruby 1.8. But in 1.9 since String#each is deprecated, the code breaks.

Not sure what is the best solution. Should it be passed as an array? In that case newline will not be send to the browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.