Offline.js | A drop-in to replacement for App Cache | Caching library
kandi X-RAY | Offline.js Summary
kandi X-RAY | Offline.js Summary
A drop-in to replacement for App Cache.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Offline.js
Offline.js Key Features
Offline.js Examples and Code Snippets
Community Discussions
Trending Discussions on Offline.js
QUESTION
In my current project using webpack with (workbox-webpack-plugin
) and workbox (with workbox-window
) I have encountered an error where the serviceworker will never respond to messages when the page is loaded at a "deep url", like "/my-path/is-nested".
It will work on "/my-path".
In a minimal reproducible environment, this is supposed to happen.
- In a new tab, app is accessed (e.g. via
https://my-app.my-name.company-dev-envs.cloud/some-unique-id
) - ServiceWorker gets registered via workbox (
.register()
) - upon registration,
messageSW
is used to ask for the SWs "version" - ServiceWorker responds using
event.ports[0].postMessage
with a string indicating the version
Is the site accessed in a "deep" path, like /some-unique-id/test, the messaging will never work.
Workbox does successfully "register" - but no events will be fired (except externalactivated
when Update on Reload
in the Application > Service Worker Tab is selected)
The serviceworker will be reported as "active and running" with no other service workers displayed. It seems to handle fetches okay too. Only messages and events never respond/fire via the wb
Workbox Window instance.
The "application" tab reports the service worker as active and running:
index.js (main entry for application)
...ANSWER
Answered 2020-Jun-18 at 11:39I was able to solve it myself. The issue was of course that the path to ./sw.js
is not correct when the user navigates to a subpath.
https://my-website.com/a-subpath/a-resource
does not resolve ./sw.js
to https://my-website.com/sw.js
but rather to https://my-website.com/a-subpath/sw.js
This was a very dumb mistake but hopefully somebody can be helped with this answer. Perhaps it would be helpful if workbox-window
didn't resolve correctly as if the registration were a success, but rejected the ./sw.js
path.
QUESTION
I have a question about caching in PWA.
I would like to let user choose a list to cache. For example:
User creating few lists, and then he choose one, to save for offline.
When he is offline he can only open 2 views:
1. smth like "u are offline, do you want to open saved list?" (if it exist)
2. View with saved list.
At this moment, I am caching all views that user visited, but can't cache views with dynamic data.
I'm using PWA.essentials to do PWA.
ANSWER
Answered 2019-Dec-29 at 15:14You are saving the user selected pages’ list at server side in offline.json and you are caching that file too. As per working of PWA cached resources are served from cache and not from server until cache is removed/cleared.
You can take 2 approach.
Whenever user adds to the offline.json you need enforce service worker to update the offline file.
You can simply store the user selecting in local storage and from there you add pages to cache list.
QUESTION
I am using offline.js with turbolinks
and on initial page load it works fine. But if I click another links then this wont work until I refresh the page. I can see the Offline.state
is down but still the view is not showing. Is there any way to manually
trigger the popup
window?
Update
Other than the offline.js
file the only js I have is this
ANSWER
Answered 2017-Mar-06 at 04:18This could be a turbolinks issue. In app/assets/javascripts/application.js
, wrap your javascript code within:
QUESTION
Something that I'm running into with a project I'm working on is, I have a single page application. I'm handling browser navigation routing on the client-side, that lets me dynamically import some modules whenever a route is matched. My routing setup looks a bit like this:
...ANSWER
Answered 2019-Oct-10 at 13:01The browser is not doing that sort of caching/deduping/whatever. You can verify this easily by calling import
from the console and toggling your network online/offline.
So the problem is most likely with the framework you're using. The caching of the first call to the route action happens somewhere in the framework. Maybe consult the documentation?
QUESTION
Usually whenever I read a blog post about PWA's, the tutorial seems to just precache every single asset. But this seems to go against the app shell pattern a bit, which as I understand is: Cache the bare necessities (only the app shell), and runtime cache as you go. (Please correct me if I understood this incorrectly)
Imagine I have this single page application, it's a simple index.html with a web component: . That
component sets up some routes which looks a little bit like this, I'm using Vaadin router and web components, but I imagine the problem would be the same using React with React Router or something similar.
ANSWER
Answered 2019-Oct-10 at 11:16Option 1 (not always useful):
As far as I can see and according to this answer, you cannot open a new window or change the URL of the browser from within the service worker. However you can open a new window only if the clients.openWindow()
function is called from within the notificationclick
event.
Option 2 (hardest):
You could use the WindowClient.navigate
method within the activate
event of the service worker however is a bit trickier as you still need to check if the file requested exists in the cache or not.
Option 3 (easiest & hackiest):
Otherwise, you could respond with a new Request
object to the offline page:
QUESTION
ANSWER
Answered 2017-Nov-25 at 00:32Using Newtonsoft Json.NET this is kinda easy to accomplish:
QUESTION
I'm having a hard time to make use of the Offline.js in NodeJS. I've used the Offline.js like the following but it always shows check()
is undefined or any other methods.
ANSWER
Answered 2017-Apr-08 at 10:52So, I came up with the following solution using the [isOnline package].1 as Offline.js doesn't work in Node or on the server side.
QUESTION
I am following the Vue.js tutorial "The Ultimate Vue JS 2 Developers Course"(Project 2) and I am running into an issue with the browser refresh on file change. I am on Kubuntu 16.04 and my system's standard browser is Chrome, but yet, every time I change a file in my project, webpack tries to open Firefox, which is not installed on my system (and I don't want to use Firefox, but Chrome).
I already went through the webpack.config.js, but I just can't figure out, where I could change settings for the browser.
webpack.config.js
...ANSWER
Answered 2018-Jan-28 at 10:38Your project is using the open
library in order to open a URL in a browser. Specifically this line, in server.js
file:
QUESTION
I'm trying to build a web-application shopping list. I want to use the html5 application cache to view the list when offline. The shopping list items are stored in local storage. On my laptop everything works fine but on my iPhone, it seems that all pages are cached while this is not my purpose.
...ANSWER
Answered 2017-Jun-18 at 17:59After a long search, I found a solution that works for me. I discovered that the application cache feature is not yet totally supported by all browsers. With the help of the link below I came to a working solution. It's not the most elegant solution but it works in Firefox, Edge and Safari.
QUESTION
I am using Offline.js to check my Internet connection in a simple web app. The problem is that i receive only the first connection message and then nothing.
...ANSWER
Answered 2017-Mar-15 at 12:13Your script works fine, unless you run it locally using the file://
scheme.
The point is that Offline.js makes requests to /favicon.ico
to the domain, it is currently running on. For the local scheme, requests to itself can yield a security threat. Therefore it is disabled by default.
- You can start Google Chrome using the
--allow-file-access-from-files
argument to make it work. - In Mac or Linux, go into the folder of your files and run
python3 -m http.server
. Then go tolocalhost:8000/
in your browser and locate your HTML file.
Using these approaches, the HTML files will be served over HTTP and it can make proper AJAX calls and Offline.js works again.
In short: Offline.js does not work in file://
schemes.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Offline.js
Make sure your server supports manifest mime types. For Apache open the mime.types and add text/cache-manifest manifest.
Add the manifest to your html tag <html manifest="appcache.manifest">.
Add offline.js.
Call offline.prime() to download everything in the DOM.
Call offline.activate() to replace DOM nodes with local storage cache.
In order to update the main html after the inital load, delete the app cache browser storage. In chrome use: chrome://appcache-internals.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page