3.143 ways to synchronize data across documents - HTTP 203

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 82

  • @Kirarak
    @Kirarak 4 года назад +69

    Yep, the sum is correct.

    • @jakearchibald
      @jakearchibald 4 года назад +12

      phew

    • @TheAlyxGreen
      @TheAlyxGreen 4 года назад +1

      came down to the comments just to check lol. At least they didn't have a typo like they did in the Squoosh.app episode.

  • @LeeSmith-cf1vo
    @LeeSmith-cf1vo 4 года назад +52

    With my user hat on - please don't over-use this kind of thing. Sometimes I will open another tab precisely because I want one to stay in its current state, for later reference. The examples mentioned in the video sound fine to me, but taking this kind of technique to the extreme could just be annoying to the user.

    • @sviat_d
      @sviat_d 3 года назад

      The existence of such technology does not really mean that it should be integrated on each site on the web

  • @lotsofloops
    @lotsofloops 4 года назад +17

    6:26 you also run into maximum connections per origin limits when using EventSource over HTTP/1.1, so if you have >6 tabs open then at least one won't be able to create an EventSource. (This is mostly fixed with HTTP/2+)
    see stackoverflow.com/questions/16852690/sseeventsource-why-no-more-than-6-connections

  • @samfrostinjapan
    @samfrostinjapan 4 года назад +4

    13:37 Butterflies in my chest-- genuine feeling of joy
    13:41 Oh, maybe some little issue
    13:42 Crushing sadness and feeling betrayed

  • @pdcx
    @pdcx 2 года назад +5

    4:11 | window.postMessage (needs window reference of another window, e.g. via window.open) | Score: 0.248
    5:57 | EventSource (HTTP event stream, cross-device) | Score: 0.492
    8:30 | window's localstorage change event (no message to current window) | Score: 0.763
    10:33 | Broadcast channel (channel->other same name channels; no safari support) | Score: 0.635
    11:39 | Service worker (window->worker->all windows) | Score: 1
    13:06 | IndexedDB Observers (experimental) | Score: 0.005

  • @Vogel42
    @Vogel42 4 года назад +31

    the math checks out:
    0.248+0.492+0.763+0.635+1+0.005 = 3.143

    • @jakearchibald
      @jakearchibald 4 года назад +19

      my reputation is safe

    • @SantoLucasST
      @SantoLucasST 2 года назад

      Yeah but can someone check if this guy's check cheks out?

  • @dikatok
    @dikatok 4 года назад +4

    Thanks for the scientifically-proven and methodological scores ❤️

  • @andrewredican1413
    @andrewredican1413 4 года назад +1

    Jake you chose a very interesting topic to discuss. I appreciate it :)

  • @nirmalghanta
    @nirmalghanta 4 года назад +6

    Waiting for observers to be implemented in Indexed DB!! Also there is an Observable in DixieJs(an idb wrapper) if anyone is interested.

  • @mariancaikovski8638
    @mariancaikovski8638 4 года назад +2

    That was really interesting. Perhaps, the best among 2020 videos

  • @ReinPetersen
    @ReinPetersen 2 года назад

    any updates on IDBObserver? Not finding much on it and wondering if it is stalled ...

  • @adasjdaksjdlkasldjas
    @adasjdaksjdlkasldjas 4 года назад

    Service worker's are fiddly and service worker messaging is even more fiddly. As for the observers discussed at the end, that's a really nice pattern, I like to use that with a Websocket to a server that stores the state, but it would of course be nice if it didn't require a server.I didn't know about the localStorage listener, thanks!

  • @cmtMiniBill
    @cmtMiniBill 4 года назад

    Isn't matchAll unsupported on Safari though? Which means that the workers broadcast method will not work on Safari? Please correct me if I am wrong

  • @maxziebell4013
    @maxziebell4013 4 года назад +1

    Great show!

  • @JaseTheAussie
    @JaseTheAussie 4 года назад

    Hurrar - you guys are getting your flow back

    • @dassurma
      @dassurma 4 года назад +3

      Wait. Did we lose it?

    • @JaseTheAussie
      @JaseTheAussie 4 года назад

      It’s looked a little ‘awkward’ vs when you guys are in the studio :)

  • @jenishngl
    @jenishngl 4 года назад +2

    gone not forgotten 6:18 ❤❤❤

    • @AgozieAni
      @AgozieAni 4 года назад

      What happened to him?

  • @Urizieli
    @Urizieli 4 года назад

    You mention that storage event is triggered when session storage is changed, but I believe session storage is not shared between different windows and the event does NOT trigger

    • @dassurma
      @dassurma 4 года назад +2

      No, we are talking about the storage event in the context of LocalStorage, not SessionStorage.

    • @jakearchibald
      @jakearchibald 4 года назад

      Yep. But also, a page and same origin s will share session storage.

  • @riddixdan5572
    @riddixdan5572 4 года назад +1

    the local storage thing, you said that you can't store objects, but you could just stringify JSON object, correct?

    • @jakearchibald
      @jakearchibald 4 года назад

      Yep, but that comes with all the limitations of JSON.

    • @riddixdan5572
      @riddixdan5572 4 года назад

      @@jakearchibald for example?

    • @jakearchibald
      @jakearchibald 4 года назад

      ​@@riddixdan5572 compared to structured cloning, JSON cannot store: circular references, BigInt, Date, RegExp, ArrayBuffer, any of the ArrayBufferViews, Map, Set, Error, ImageData, ImageBitmap, Blob, File… there are probably more I'm forgetting.

    • @riddixdan5572
      @riddixdan5572 4 года назад

      @@jakearchibald Hmh, fair enough, but there are always libraries that can imitate it somewhat. but yeah, probably not everything, I guess circular reference would be the easiest to imitate. Can't say the same for other examples you brought tho.

    • @jakearchibald
      @jakearchibald 4 года назад

      @@riddixdan5572 Oh yeah you can make your own serialisation format if you must. But why not use one of the other storage systems that does all that for you?

  • @chrisgilardi
    @chrisgilardi 4 года назад +3

    1:53 Joy-Con 👀

  • @tomayac
    @tomayac 4 года назад +2

    There is a feature request bug for BroadcastChannel in Safari: bugs.webkit.org/show_bug.cgi?id=161472. It’s currently blocked by a spec issue around partitioning: github.com/whatwg/html/issues/5803.

    • @kalleguld
      @kalleguld 2 года назад +1

      It works on Safari now (since march 2022)

  • @jameslockwood
    @jameslockwood 4 года назад

    BroadcastChannel is really easy to polyfill in Safari and older browsers, for those who aren't aware :)

    • @jakearchibald
      @jakearchibald 4 года назад +2

      Via what mechanism?

    • @sb_dunk
      @sb_dunk 3 года назад

      @@jakearchibald I guess we'll never know :(

  • @JonathonBroughtonUK
    @JonathonBroughtonUK 3 года назад

    Who can we lobby to get them working on the ID Bob Server?

  • @Flamel001100
    @Flamel001100 4 года назад +1

    correct sum, no worries

  • @rastasponch
    @rastasponch 4 года назад

    What do you think about accessiblity ? Section 501 for example.

  • @airmust2265
    @airmust2265 2 года назад

    Hi, thanks for this video!
    We solved the task of synchronizing tabs through service worker, but we came across the fact that sw periodically falls asleep and does not respond to messages from its customers. Please tell me how to proceed in this case and is the estimate of 1.000 correct?
    We started using shared workers for synchronization, and it has proven itself perfectly

    • @jakearchibald
      @jakearchibald 2 года назад +1

      Sending the service worker a message via fetch or postMessage should always wake it up. If you've found a case where it doesn't, it's a bug. However, if you're expecting the service worker to stay awake when it isn't doing anything… that isn't what it's designed for.

    • @airmust2265
      @airmust2265 2 года назад

      ​@@jakearchibald No, we do not expect and do not want the worker service to always be in an active state, however, we hoped that the postMessage message from the tab (his client) would wake him up.
      Moreover, this behavior is very difficult to catch. Anyway, we switched to shared workers, please tell me how much better this solution is.
      Or is it better to deal with the service worker after all?
      I like the service worker because it keeps the list of clients always up to date. In turn, in the shared worker, you need to monitor the customers yourself

    • @jakearchibald
      @jakearchibald 2 года назад +1

      @@airmust2265 the service worker should definitely wake up on postMessage. Shared worker is good too, but not supported on mobile

    • @airmust2265
      @airmust2265 2 года назад

      @@jakearchibald understood thanks! I will also experiment with the service worker, I will try to understand why he does not come to life in me

  • @ELStalky
    @ELStalky 4 года назад

    If you have server data to sync, i really like web sockets for that; keeps all instances on all devices synchronized.

    • @jakearchibald
      @jakearchibald 4 года назад +2

      It works pretty much the same as EventSource in terms of synchronising capability.

  • @AlanChandler42
    @AlanChandler42 4 года назад

    I can't find any mention on the web that Safari on IOS supports the client API . Does clients.MatchAll work with it? see at 12:06 - so why does this method score 1.000

    • @jakearchibald
      @jakearchibald 4 года назад

      I'm pretty sure it does

    • @jakearchibald
      @jakearchibald 4 года назад

      I mean, if it doesn't, then I've messed up my scoring

    • @AlanChandler42
      @AlanChandler42 4 года назад

      @@jakearchibald I spent yesterday building a service worker and then seeing if it would work on a Macbook Air and an iPad and it appears to work fine (other CSS problems but ...). The way I retrieve this data is by actually adding to my "api" name space a "service" section where the service worker responds and never passes the request to my server.
      ```
      const api = /^\/api\/(service|config|session|profile|approve|gadm)\/(\w+)|(\d+)\/(admin|user)\/(\w+)$/i;
      self.addEventListener('fetch', (event) => {
      const requestURL = new URL(event.request.url);
      if (/^\/api\//i.test(requestURL.pathname)) {
      //We have an api call, so deal with it appropriately
      const matches = api.exec(requestURL.pathname);
      if (matches === null) {
      //let the browser do its own thing
      } else {
      switch (matches[1]) {
      case 'service':
      //service worker request , lets do it
      switch(matches[2]) {
      case 'tab':
      event.respondWith(
      self.clients.matchAll({includeUncontrolled: true}).then(clients => new Response(clients.length.toString(),{status: 200, headers: {
      'Cache-Control': 'no-cache',
      'Content-Type': 'text/plain; charset=US-ASCII',
      } })));
      break;
      default:
      event.respondWith(new Response('', { status: 404 }));//unknown so send a 404
      }
      break;
      case 'config':
      ...
      ```

  • @victornpb
    @victornpb 4 года назад

    if you want to sync tabs across sub domains, you will have to create a JavaScript cookie and do pooling on it. YIKES IK.
    I don’t know any other way other than going server side.

    • @jakearchibald
      @jakearchibald 4 года назад

      I would use s and postMessage for that. Avoids polling.

  • @paulmel4411
    @paulmel4411 Год назад

    I'm missing SharedWorker in this episode!

    • @paulmel4411
      @paulmel4411 Год назад

      Well, postMessage should summarize it. And it's mentioned in BroadcastChannel.
      BroadcastChannel should have a better score nowadays, given its support.

  • @loading.express
    @loading.express 4 года назад +2

    😂😂😂 thank you for you show.

  • @informativecontent4778
    @informativecontent4778 4 года назад +1

    Firefox the best browser ever

  • @IAmOxidised7525
    @IAmOxidised7525 2 года назад

    Local storage ?

  • @chaos_monster
    @chaos_monster 4 года назад

    IDBObserver would be a great solution to replace RxDB

  • @samuel.00
    @samuel.00 4 года назад +7

    i do not think i can handle the thumbnail being a mirror of the actual video

  • @wepranaga
    @wepranaga 4 года назад

    ahh the beauty of the web :(

  • @jumoogde
    @jumoogde 4 года назад +1

    You forgot websocket

    • @wtho
      @wtho 4 года назад

      They were talking about offline ways

    • @jakearchibald
      @jakearchibald 4 года назад +1

      It works pretty much the same as EventSource in terms of synchronising capability.

    • @wtho
      @wtho 4 года назад

      @@jakearchibald can you use websockets to communicate between documents directly?

    • @jakearchibald
      @jakearchibald 4 года назад

      @@wtho nah

  • @daheck81
    @daheck81 4 года назад +3

    8:46 Well, you can store objects as json tho

    • @daheck81
      @daheck81 4 года назад +1

      Emrah ATILKAN You can

    • @dassurma
      @dassurma 4 года назад +4

      Only a very specific subset of objects. You can have cyclic structures in JavaScript, but that doesn't translate to JSON. JSON can't handle Maps, Sets, ArrayBuffer/ArrayBufferViews, classes, prototypes... lots of things can get lost when stringifying.

    • @daheck81
      @daheck81 4 года назад +1

      Surma Exactly, and this should be enough for most use cases. Needing to store abstract objects on the client side is a pretty rare scenario. And in some cases you can prepare complex object(s) before the "stringification". But I get your point!

    • @daheck81
      @daheck81 4 года назад

      Emrah ATILKAN Well it is still a JSON String though but technically not an object anymore, that’s true. Nevertheless you are still able to store objects, just not directly as objects while being in the storage. Got me there.

  • @troooooper100
    @troooooper100 4 года назад +1

    you forgot websocket... for every user create a channel in backend and broadcast to all instances

    • @sjorsborsoborsobors
      @sjorsborsoborsobors 4 года назад

      I guess you'd be doing about the same as SSE

    • @jakearchibald
      @jakearchibald 4 года назад +1

      @@sjorsborsoborsobors yeah, the only difference is it isn't broadcast only

    • @troooooper100
      @troooooper100 4 года назад

      @@sjorsborsoborsobors yea, almost the same in terms of pros and cons.

  • @danielbark
    @danielbark 4 года назад

    Clappy time XD

  • @troooooper100
    @troooooper100 4 года назад +1

    wait who is gone but not forgotten?

  • @hobbyturystaSEO
    @hobbyturystaSEO 4 года назад

    Https 3143