Skip to content

Releases: noreastergroup/coldwire-rails

0.5.0

Choose a tag to compare

@stuyam stuyam released this 17 Sep 19:56

What's Changed

It will add turbo frame ids and formats to the cached urls as url params that don't get sent to the server but attach settings for controller actions that return multiple formats or respond to turbo frames.

As an example, it allows all of these respond_to responses to be cached differently per URL:

def show
  respond_to do |format|
    format.html { render html: (turbo_frame_request? ? FRAME : PAGE).html_safe }
    format.json { render json: { body: "json" } }
    format.csv { render plain: "a,b,c" }
    format.xml { render xml: "<report/>" }
    format.text { render plain: "plain" }
  end
end

For precaching urls you can also optionally specify turbo frame and formats to cache accordingly:

Coldwire.configure do |config|
  config.auto_sync do |sync|
    sync.precache_urls = ->(controller) {
      [
        "example/url",
        { url: "example/url_2", frame: "card" },
        { url: "example/url_3", format: :json },
      ]
    }
  end
end

Also since turbo streams are meant to be in response to form submissions, turbo streams are intentionally ignored now from caching.

Full Changelog: 0.4.0...0.5.0

0.4.0

Choose a tag to compare

@stuyam stuyam released this 17 Sep 00:56

What's Changed

  • Updated the offline page to restructure storage and downloads.
  • Updated the storage so when you change storage size it triggers a garbage collection.

Full Changelog: 0.3.0...0.4.0

0.3.0

Choose a tag to compare

@stuyam stuyam released this 11 Sep 21:26

cache_origins is now cacheable_hosts, and takes bare hosts: "tiles.example.com" rather
than "https://tiles.example.com". The scheme was never carrying information — a worker
runs only on a secure page, and a secure page cannot fetch http — so it was a required
prefix with exactly one possible value. Requests are matched on a URL's host, so a port
belongs where it is not the default and localhost:3001 matches that port and no other.
A scheme raises at boot, naming what to write instead.
Full Changelog: 0.2.0...0.3.0

0.2.0

Choose a tag to compare

@stuyam stuyam released this 11 Sep 19:52

What's Changed

New Contributors

  • @stuyam made their first contribution in #1

Full Changelog: 0.1.0...0.2.0

0.1.0

Choose a tag to compare

@stuyam stuyam released this 10 Sep 20:13

Initial release of coldwire-rails 🎉

First release. The API may still change before 1.0.

  • bin/rails coldwire:install. Mounts the engine at /offline, writes an initializer
    with every option and its default, registers the Stimulus controller, and tags the
    layout. Safe to run twice.
  • Offline support switch in the status header on the offline settings page. Off deletes
    what is stored, unregisters the worker, and hides the rest of the page.
    config.caching_enabled_by_default is the starting position of the switch (on). A device
    remembers the choice.
  • Service worker and offline fallback. A mountable engine serves the worker; when there is
    no cached copy and no network, a full page or a <turbo-frame> — both overridable — stands
    in. Built to satisfy Hotwire Native, which is stricter than a browser.
  • Precaching. auto_sync.precache_urls is a list of URLs computed in Ruby, fetched along
    with the subresources those pages reference.
  • The cache's requests carry the app's user agent, by way of a cookie. A worker's own
    fetches cannot: Hotwire Native sets the agent on the web view, ServiceWorkerWebSettings has
    no equivalent, and fetch may not set one — so on Android everything precached came back
    rendered for a browser. Each page writes its agent into coldwire-user-agent, which the
    browser attaches to every same-origin request, and a middleware puts it back.
  • cache_as_you_go names the pages kept as somebody browses — default ["/*"], every
    path. An empty list stores nothing by browsing. A stored page brings what it asks for
    — its stylesheets, scripts and images are stored with it whatever the lists say, because
    a page held without them is the offline equivalent of not holding it. never_cache
    is the one veto over storing anything, by any route in; it is not never_intercept,
    which stops the worker touching a request at all and so fails outright offline.
  • Automatic syncing on an interval, refetching anything older than max_age, resuming
    across page loads when a run is cut short.
  • Offline settings page at the mount point: connection status, force offline, an Auto Sync switch
    with a countdown and live progress. The list of every cached URL is under Inspect cache,
    closed until you open it and remembered after that.
  • Nothing served from the cache is data-turbo-track="reload". Turbo will not render a
    page whose tracked elements differ from the current page's; it reloads instead, which
    offline buys nothing and which Hotwire Native can hang on. Asset digests change with every
    deploy, so any page cached before the current one was built disagrees with it — no
    configuration could have reconciled that. This replaced the offline_head setting, whose
    whole job was keeping the fallback's tracked elements in step with the layout by hand.
  • One cache entry per URL. cache.put() replaces an entry only where the two agree about
    Vary, and Rails answers HTML with Vary: Accept — so a page fetched by precaching
    (*/*) and the same page visited by Turbo (text/html) are kept as two records, and the
    list grows a copy per distinct Accept. Writing a page now retires the URL first. Range and
    chunk entries, which share a path with their own query, are left alone.
  • Allow and block lists written as route patterns ("/sites/:id/card") or Regexps.
  • Cache identity. The cache is dropped when the signed-in user changes.
  • Cross-origin caching for origins you nominate, and Range caching for tiles and
    media that would otherwise be uncacheable.
  • Downloadable archives. Large files somebody can choose to keep, fetched in chunks so an
    interrupted download resumes.
  • window.Coldwire — isOffline(), isForcedOffline(), cachedAt(), onChange() — plus
    data-coldwire-offline on any HTML served from cache.

Full Changelog: https://github.com/noreastergroup/coldwire-rails/commits/0.1.0