{"id":15638799,"url":"https://github.com/rossta/serviceworker-rails-sandbox","last_synced_at":"2025-04-15T06:13:21.280Z","repository":{"id":37693028,"uuid":"57448450","full_name":"rossta/serviceworker-rails-sandbox","owner":"rossta","description":"Service Workers on Rails demo app with the serviceworker-rails gem","archived":false,"fork":false,"pushed_at":"2022-12-14T02:05:43.000Z","size":1242,"stargazers_count":89,"open_issues_count":19,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-15T06:13:15.184Z","etag":null,"topics":["rails","rails-asset-pipeline","service-worker","serviceworker-rails"],"latest_commit_sha":null,"homepage":"https://serviceworker-rails.herokuapp.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rossta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-30T15:16:55.000Z","updated_at":"2024-01-29T17:51:14.000Z","dependencies_parsed_at":"2023-01-28T16:16:36.319Z","dependency_job_id":null,"html_url":"https://github.com/rossta/serviceworker-rails-sandbox","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fserviceworker-rails-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fserviceworker-rails-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fserviceworker-rails-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fserviceworker-rails-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rossta","download_url":"https://codeload.github.com/rossta/serviceworker-rails-sandbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016638,"owners_count":21198833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","rails-asset-pipeline","service-worker","serviceworker-rails"],"created_at":"2024-10-03T11:23:14.757Z","updated_at":"2025-04-15T06:13:21.260Z","avatar_url":"https://github.com/rossta.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Service Workers on Rails\n\nThis sandbox demonstrates various use cases for \"Service Workers on Rails\". Integration of Service Workers with the Rails asset pipeline is provided by the [serviceworker-rails](https://github.com/rossta/serviceworker-rails) gem.\n\n## Background\n\nThe [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) is coming. Service Workers are scripts that act as a proxy between the browser and the server. Among other things, Service Workers can be used to:\n\n- enable the creation of effective offline experiences\n- increase perceived performance while online\n- access push notifications and background sync APIs.\n\nService Workers are scripts that live outside the context of a rendered page.\nThis means that there are some considerations for hosting Service Workers:\n\n- service workers must be served over HTTPS\n- service workers must be served within the \"scope\" of the page(s) they control ([pending override capability](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-allowed))\n- service workers should not be cached: browsers install service workers in the background so requesting and evaluating\nthese scripts will not tie up page rendering\n\n### Rails integration\n\nSo you want to use Service Workers in your Rails app? Consider that the Rails asset pipeline bundles JavaScript assets so that they're typically finger-printed, heavily cached, and served out of the `/assets` directory. While we'd like to take advantage of the asset pipeline for transpiling our Service Worker scripts just like any other JavaScript assets, we need flexibility for how these assets are served to the client.\n\nThis is where the [serviceworker-rails](https://github.com/rossta/serviceworker-rails) gem comes in. Using `serviceworker-rails` in your Rails app allows you to map Service Worker endpoints to bundled Rails assets and adds the appropriate (configurable) response headers. You can still take advantage of Rails pipeline with Service Workers in development and production!\n\nThe sandbox serviceworker initializer in  [`config/initializers/serviceworker.rb`](https://github.com/rossta/serviceworker-rails-sandbox/blob/master/config/initializers/serviceworker.rb) provides several examples for customizing how service worker endpoints should map to assets in the Rails asset pipeline. Corresponding serviceworker implementations for the examples can be found in [`app/assets/javascripts`](https://github.com/rossta/serviceworker-rails-sandbox/tree/master/app/assets/javascripts).\n\n## Resources\n\nExamples in this sandbox are inspired by a variety of resources:\n\n* [Mozilla's Service Worker Cookbook](https://github.com/mozilla/serviceworker-cookbook/)\n* [Jake Archibald's Offline Cookbook](https://jakearchibald.com/2014/offline-cookbook/)\n* [Pony Foo Service Worker Articles](https://ponyfoo.com/articles/tagged/serviceworker)\n\n## Development\n\nCheck out the project with git, run `bundle install` and copy the\n`database.yml.example` to `database.yml` and edit to fit your needs.\n\nYou could also try running with Docker. The `docker-compose.yml` assumes the\nexistence of an `.env.docker` file. You may want copy the `.env.docker.example`\nfile and set up your own environment variables. Assuming you have Docker\ninstalled and running, you could simply try running `docker-compose up`. YMMV.\n\nIf desired, for certain features you'll need Twitter app credentials. Example keys can be found in\n`.env.docker.example`.\n\nGood luck!\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rossta/serviceworker-rails-sandbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossta%2Fserviceworker-rails-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frossta%2Fserviceworker-rails-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossta%2Fserviceworker-rails-sandbox/lists"}