Browser Caching Best Practices, When to use no-cache vs max-age without breaking your site

Sdílet
Vložit
  • čas přidán 25. 06. 2024
  • Caching is the hardest problem in building software, and having the browser cache is not any different. In this video, I'll discuss Jake Archibald's article
    jakearchibald.com/2016/cachin...
    0:00 Intro
    2:00 Pattern 1: Immutable content + long max-age
    5:40 Pattern 2: Mutable content, always server-revalidated
    8:00 max-age on mutable content is often the wrong choice
    12:20 CDN and Caching
    Article
    jakearchibald.com/2016/cachin...
    / jaffathecake
    🎙️Listen to the Backend Engineering Podcast
    husseinnasser.com/podcast
    🏭 Backend Engineering Videos
    backend.husseinnasser.com
    💾 Database Engineering Videos
    • Database Engineering
    🏰 Load Balancing and Proxies Videos
    • Proxies
    🏛️ Software Archtiecture Videos
    • Software Architecture
    📩 Messaging Systems
    • Message Queues & PubSu...
    Become a Member
    / @hnasr
    Support me on PayPal
    bit.ly/33ENps4
    Stay Awesome,
    Hussein
  • Věda a technologie

Komentáře • 46

  • @Fireship
    @Fireship Před 3 lety +62

    Nice video! Jake Archibald is always an excellent resource

  • @mahdikarimi6467
    @mahdikarimi6467 Před 3 lety +14

    I watch every second of your work with unlimited amount of passion and joy! keep it up

  • @mohammedsalman3397
    @mohammedsalman3397 Před 3 lety +5

    i just love my life when i see a video of yours in my feed

  • @sircosm
    @sircosm Před 3 lety +3

    I was looking up cache-control stuff this morning and BOOOOOM up comes your new video! Thanks so much for the excellent content!

  • @smoothbeak
    @smoothbeak Před 3 lety +2

    Wow, this is really great.
    First of all great content from Jake Archibald, and then the further explanations by Hussein, that is an excellent combo, and I can say I feel rather educated on caching now, and before the video I didn't know a damned thing!

  • @tonynguyen4007
    @tonynguyen4007 Před 3 lety +2

    Hey Hussein, we are connected somehow. I have been checking on Cache-content this morning and your video came up, so I liked it before watching.
    Thank you and Jake for great content.

  • @hangtran4863
    @hangtran4863 Před 2 lety

    out-of-this-world demonstration skill, thank you a lot Mr.Hussein ^^

  • @avi12
    @avi12 Před 3 lety +9

    6:16 I'm pretty sure "./sw.js" means "service worker"

    • @ashrafsayed1058
      @ashrafsayed1058 Před 3 lety

      for sure it is

    • @hnasr
      @hnasr  Před 3 lety +4

      You can tell I never used service workers 😅

  • @ahmedkhudhair8035
    @ahmedkhudhair8035 Před 3 lety

    Good research , Dr. Hussain Nasser 🌹

  • @oddocid9734
    @oddocid9734 Před rokem

    This is relly valuable. Thanks!

  • @Tsirikul1
    @Tsirikul1 Před rokem

    Thank you so much. Nice Video!!

  • @sandeepnegi4939
    @sandeepnegi4939 Před 3 lety

    These videos are so helpful love from. 🇮🇳

  • @kesc23
    @kesc23 Před 2 lety

    Dude, You just saved my work! LOL

  • @autohmae
    @autohmae Před 3 lety

    You picked a great article to explain this topic. A great introduction into Sevice Workers if you want to cover it (which I fully understand if you don't want to :-) ).
    6:16 my guess is /sw.js is service worker, because these fake chat conversations are how service workers work.
    Tip: force refresh in a browser is actually the key combo: ctrl + F5
    13:49 yep, it's because you'd probably use versioning (pattern 1 in the article) in the filenames/path for the static files (CSS/JS/images).
    Yeah, Jake has been doing this for many years and it shows.

    • @hnasr
      @hnasr  Před 3 lety

      I want to cover SW and PWA but something deep inside tells we are thats over engineering the web. hey I know how to setup a proxy if I want to. I might be wrong

    • @autohmae
      @autohmae Před 3 lety +1

      @@hnasr Actually SW and PWA are a big deal they finally make offline web apps possible. Much better than HTML5 offline support (which was a failed solution). You were the one who always said it's about the why things are done. Well, it might seem over engineering, but it's because it's meant for offline support.

  • @salmaanakbar
    @salmaanakbar Před 3 lety

    Just searching for this today and you came up with. May ALLAH PAK bless you sir ❤️

  • @marksaravi7160
    @marksaravi7160 Před 8 měsíci

    You are the best ❤❤❤

  • @sabuein
    @sabuein Před rokem

    Thank you.

  • @hashiromer7668
    @hashiromer7668 Před 3 lety +2

    I am watching so much of your videos that I saw you in my dream tonight 😂.
    It was pretty detailed but the only thing i remember now is that it was about some classified project, dang it was pretty interesting.

  • @Septumsempra8818
    @Septumsempra8818 Před 9 měsíci

    A django version of this would be gold

  • @zedmagdy
    @zedmagdy Před 3 lety

    btw Hussein sw.js refers to ServiceWorker.js it's a good idea to talk about PWA as big companies like Microsoft started to use it on something like Office etc

  • @Cosmicakash
    @Cosmicakash Před 2 lety

    Hey Hissein, with both no-cache and must-revalidate a 304 status code would be returned to the user if 80-90% of the content is like evergreen content..and this load of 304s would appear in Google search console, which is kinda issue for an SEO person...is there a smart way to avoid having 304 in GSC??

  • @venkateshpachigulla
    @venkateshpachigulla Před 2 lety

    I met Jake Archibald directly and took pic with him also in one meetup in India.

  • @adsourcesales1037
    @adsourcesales1037 Před rokem

    Hi,
    I have a problem with browser caching.
    Once logged in moving to pages visited previously as anonymous user, causes their cached version to be displayed. It means that “Log in” link will appear, despite the fact that user is already logged. Refreshing page will correct menu link, displaying “Log out”, but it can’t be a solution from user point of view.
    I have the caching plugin disabled now. I went through this issue with the hosting provider and asked them to exclude caching of pages like: /my_account/, /cart/, /checkout/ and others, but still the same situation.
    Please advise what can be the solution. How to make login / logout links cache independent?

  • @omarabdelkader5214
    @omarabdelkader5214 Před 3 lety

    ربنا يبارك لحضرتك وكل عام وحضرتك بخير

  • @ch94086
    @ch94086 Před 3 lety

    Great topic! Far too often I see poor back ends disable cache and set modification date as now. They want to maximize hits, even if users suffer. Many back ends are designed assuming there is no caching.
    On the other hand, I've had lots of problems because browsers ignore the no cache, etc. so I have to add hidden fields to forms with random numbers to disable caching. Maybe it's better now, but I'm skeptical. AOL was the worst. Hussein, hopefully you are too young to know about AOL.

    • @hnasr
      @hnasr  Před 3 lety +1

      Thanks Carl, correct some backends used to disable caching on purpose for tracking reasons. (Hulu comes to mind)

  • @mtnrabi
    @mtnrabi Před 3 lety

    Why use E-Tag over saving and comparing last modified date?
    Also, in no-cache - isn't it a bit of an overhead of the cache always goes to the server anyways?
    Tell my your thoughts!

    • @hnasr
      @hnasr  Před 3 lety +1

      Modified date is great but not applicable . Resources might get updated but content didn’t really change. Or if there isn’t a static asset and the resource is dynamic (db query)
      Yes no-cache always go to the server but Remember we save on bandwidth, so its costly yes but less costly than no caching at all (no-store) where we always hit the server and always bring back full content

  • @pajeetsingh
    @pajeetsingh Před 3 lety

    Bro I hate to tell but you are so much better than TechLead.

  • @ryanslab302
    @ryanslab302 Před 3 lety +1

    At one company I worked at, we had a caching issue in our SaaS solution that pissed customers off so much, so many times, the whole engineering team got laid off. We tried so hard to fix it but after every deployment, it would appear again and again. There were other problems too but telling customers to clear their cache every month to use our app was the last straw. CloudFront, CORS and .NET Core tokens. Bleh.

    • @hnasr
      @hnasr  Před 3 lety

      Building performant scalable apps are hard! Sorry to hear that Ryan.

    • @lardosian
      @lardosian Před 3 lety

      Ryan I'm working solo in my first dev job building a PWA with AWS Amplify which uses Cloudfront, this issue is giving me nightmares and I'm beginning to hate web development because of it, throw service workers into the mix and I'm just ready to tear my hair out. Why does this have to be so complicated and difficult.

  • @aksidhu8121
    @aksidhu8121 Před 3 lety

    I need to implement HLS and DASH protocol for video streaming, can you please help me ,Sir.
    what should I do?
    I know only VS code.

  • @mrnobody1286
    @mrnobody1286 Před 3 lety +1

    The guy who dislike button should be removed from his videos o_O

  • @flaviubura4443
    @flaviubura4443 Před 3 lety

    first :)

  • @lardosian
    @lardosian Před 3 lety +1

    This whole caching thing gives me nightmares, I just hate it.