Replies: 49 comments
-
I'd absolutely love to see this working too, along with explanations/documentation/example about it. Note that next/prefetch doesn't yet really allow offline behaviour, because it doesn't prefetch data: #740 Not directly related to Next.js but I also wonder how much data can actually be kept offline (e.g if a webapp has videos etc -- is there some hard limit in the browser? And what about mobile?), how the user could specifically ask for one thing to be pre-downloaded for later, etc. I also previously mentioned things here: #24 (comment) (before next/prefetch was a thing). |
Beta Was this translation helpful? Give feedback.
-
There are varying data limits in different platforms, browsers and versions. You can test the limits in the "Browser storage abuser": https://demo.agektmr.com/storage/ The standardized method which is intended for offline storage and caching is IndexedDB. It is now supported even in iOS Safari (v10), but there it has performance issues. Otherwise it has wide support now: http://caniuse.com/#feat=indexeddb E.g. PouchDB still uses WebSQL instead of IndexedDB on Safari. pouchdb/pouchdb#5572 PouchDB has a nice summary of data limits: https://pouchdb.com/faq.html#data_limits (slightly out of date) You can also query for your current quota and request more persistent storage in some browsers: https://jakearchibald.com/2014/offline-cookbook/#cache-persistence Another way would be to use long cache expiration values and immutable cache control together with service workers. This would easily allow user specified caching, just by making a http request for each selected resource. This would also work quite nicely in old browsers. But to be able to maintain and manually delete various caches to avoid limits would only be possible in browsers supporting service workers. Just remember, when you run out of space, the browser can evict an entire origin at a time until it is within limits: |
Beta Was this translation helpful? Give feedback.
-
Another useful article by Addy Osmani: https://medium.com/dev-channel/offline-storage-for-progressive-web-apps-70d52695513c#.9vja3t8gp Apparently there is also a Storage api being worked on: https://storage.spec.whatwg.org/ This allows actually persistent storage: |
Beta Was this translation helpful? Give feedback.
-
IMO making a site/app work offline involves a lot of decisions a framework shouldn't take by itself. I'll work on an example on a site working offline with a service worker but there are different techniques for different kind of apps. |
Beta Was this translation helpful? Give feedback.
-
thanks @impronunciable . Do you plan to use webpack-offline or something else? what kind of decisions are you talking about? I think we can divide the problem in two main issues:
|
Beta Was this translation helpful? Give feedback.
-
@servermeta it really depends on your case. I'm finishing implementing an aggressive caching strategy without using plugins, just a custom server and a strategy from https://serviceworke.rs/ |
Beta Was this translation helpful? Give feedback.
-
I have it working here. Battled a lot with Offline-Plugin, had some issues with the .next directory then i switched to sw-precache-webpack-plugin, ignored .next directory and served all assets to the sw |
Beta Was this translation helpful? Give feedback.
-
thank you @ooade , well done, you saved me a lot of time. Anyhow I see that state does not persist between refreshes, reloads. I'll try to think how to add this feature. |
Beta Was this translation helpful? Give feedback.
-
thank @ooade . By localhost you mean a local db, like mongodb, or localstorage? I think we should divide the problem: offline data retrieving should be left to the dev, while we could preserve redux state. Check this: https://github.com/rt2zz/redux-persist with this we can store state in localstorage, so it can persist between refreshes, reloads, tabs and sessions. |
Beta Was this translation helpful? Give feedback.
-
Hey folks. My team at Google work on a few Service Worker libraries (with Webpack plugins) like https://github.com/GoogleChrome/sw-precache and https://github.com/GoogleChrome/sw-toolbox used on React/Webpack heavy sites like Lyft, Housing.com, Flipkart etc. If Next decides to explore offline support we would be happy to share some pointers. I think there's great opportunity for prescribing patterns like PRPL out of the box, given code-splitting is already being done. Production-only Service Worker caching would be a neat addition. In addition to giving you instant repeat loads for those pages, it would also opt you early on into V8's code caching so your parse/compile times for repeat visits would be lower than today. Feel free to holler if any of this is interesting @rauchg :) |
Beta Was this translation helpful? Give feedback.
-
@addyosmani offline support is one of our top priorities post 2.0 stable |
Beta Was this translation helpful? Give feedback.
-
@rauchg any estimation regarding 2.0 stable release date? |
Beta Was this translation helpful? Give feedback.
-
@Ajar-Ajar 2.0.0 was released today. |
Beta Was this translation helpful? Give feedback.
-
@rauchg is the offline-first support going to be tracked here or are you going to create another issue for it? |
Beta Was this translation helpful? Give feedback.
-
Please also see the newly open-sourced redux-offline by @jevakallio. Would be awesome to have a next + redux-offline example. |
Beta Was this translation helpful? Give feedback.
-
@ssured @sedubois I made a little plugin that works the same way as the plugins that Zeit launched the other day .. it should alleviate offline next apps and be pretty straight forward plugging in to your existing apps Let me know if you have any feedback! https://github.com/hanford/next-offline |
Beta Was this translation helpful? Give feedback.
-
@hanford thanks for making our life a bit easier |
Beta Was this translation helpful? Give feedback.
-
For anyone else still deciding on what to do moving forward, I also made use of the sw-precache webpack plugin with relative ease (example, again). |
Beta Was this translation helpful? Give feedback.
-
I was using my own solution but have switched to the solution provided by hanford. I had to make a few modifications in next.config.js to stop the plugin auto registering the service worker, but it seems to be working well. I now just need to figure out how I can get this working with my custom server. For example I have a route setup as article/:slug. When I visit one of these urls the service worker is trying to dispatch a document for that url. Anybody know how I can stop that and make it serve article instead? This is related to settings in Workbox I guess. |
Beta Was this translation helpful? Give feedback.
-
Should we still be expecting any integration of service workers or offline support in future NextJS releases? Looks like some people were previously saying it was a priority feature, but this issue has been open for over a year and a half... |
Beta Was this translation helpful? Give feedback.
-
@caribou-code I can't speak for the Zeit team on their plans for Next.js, but I wrote this awhile ago: https://github.com/hanford/next-offline that allows you to automatically generate a service worker that will work offline. I've used it in several applications and it's worked pretty well. Under the hood it's utilizing googles workbox, which is a very exciting project: https://developers.google.com/web/tools/workbox/ Some examples where I use |
Beta Was this translation helpful? Give feedback.
-
@hanford I was just using next-offline before posting on here and it's pretty good! In fact it's the only solution I've managed to implement so far that actually works. Good work! However, I did really want to get a solution working with sw-precache-webpack-plugin because there's an example of this in the NextJS repo, although I can't work out how to configure it to cache and serve all my Next files through the service worker. That plugin seems to be quite popular as well. |
Beta Was this translation helpful? Give feedback.
-
I created NextSimpleStarter a year ago to help resolve this issue. But, it came to my notice that sw-precache alone won't be able to meet most offline requirements so we recently moved to using workbox which solves most of them. Although, I am yet to update it to current standards(icon sizes and so on), which I will fix in few days. Feel Free to give it a trial. Drop an issue if you don't find it satisfying. |
Beta Was this translation helpful? Give feedback.
-
@hanford This looks great. It runs for me in development mode but there's no service worker in that mode. I can't tell from your readme how to make it work in production mode and with a service worker and without a node server. I also deploy my app to Netlify and I've been using @ooade This looks great too, but I got an error when starting it. Changing "serverless" to "server" per your instruction fixed that error but then I got the following error
|
Beta Was this translation helpful? Give feedback.
-
@dancancro you should definitely be able to use Mind opening an issue in |
Beta Was this translation helpful? Give feedback.
-
@hanford I can do that if you want but I did nothing special and I'm not suggesting anything's broken about the starter. The steps to reproduce the problem are simply your instructions. The only problem is that I don't know how to run it in production mode. Judging from this condition a service worker is not supposed to be registered in dev mode, so what happened for me is expected behavior. I just need some instructions - how to run it in production mode, and if |
Beta Was this translation helpful? Give feedback.
-
@dancancro I understand, but that discussion shouldn't be happening here, this is certainly not an issue with Next.js itself. Please open an issue over here and I'd be happy to take a look / answer questions you might have. The community doesn't benefit if we have a discussion in an unrelated issue/repo |
Beta Was this translation helpful? Give feedback.
-
I recently created an easy to use zero config PWA plugin for Next.js: next-pwa |
Beta Was this translation helpful? Give feedback.
-
next-offline VS next-pwa comparison can be found in the discussions: #13810 (comment) |
Beta Was this translation helpful? Give feedback.
-
Hello everyone, I am trying to create a PWA using next js with offline support without any libraries My PWA is installable and works well however when I want to cache resources, I have an issue. My app is working well offline if I put a "offline.html" file in my /public folder. Am I missing something here ? |
Beta Was this translation helpful? Give feedback.
-
Offline support is very useful, and is crucial for creating a modern PWA. Along with HTML manifests it helps to bridge the gap between a website and a native app.
This feature has two different flavours:
Offline support: This is the ability to navigate the site even when offline, if the site has been loaded while online. This should be the easiest feature to implement.
Offline first support: This is the ability to open the site even when offline, even if the site has not been loaded in the browser.
Both should be doable thanks to
webpack-offline
plugin. Anyhow since I'm learning both React and Next.js at once, I haven't been able to make it work yet.Steps to make it work:
webpack-offline
npm install offline-plugin --save-dev
next.config.js
in your root folderThis is the step I'm having problem with. I think you should do it in a component, inside
componentDidMount
, inside the top level.This issue is both a reminder for me to keep working on this, and a request for help from someone more knowledgeable.
Beta Was this translation helpful? Give feedback.
All reactions