<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kevin Basset on Medium]]></title>
        <description><![CDATA[Stories by Kevin Basset on Medium]]></description>
        <link>https://medium.com/@kevinbasset?source=rss-39df85b82f79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wwzMirzqEaaVwuk_ncW22g.jpeg</url>
            <title>Stories by Kevin Basset on Medium</title>
            <link>https://medium.com/@kevinbasset?source=rss-39df85b82f79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 13:12:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kevinbasset/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to fix iOS push subscriptions getting terminated after 3 notifications]]></title>
            <link>https://javascript.plainenglish.io/how-to-fix-ios-push-subscriptions-getting-terminated-after-3-notifications-26b9ca186aaa?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b9ca186aaa</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[progressive-web-app]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Fri, 30 Jun 2023 03:29:24 GMT</pubDate>
            <atom:updated>2023-07-05T04:17:08.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*3KTpPnQ3fNHD8Sm5.jpg" /></figure><p>With iOS 16.4, Apple has added push notifications to installed PWAs. However, you may have noticed that iOS push subscriptions appear to be automatically terminated after 3 push notifications.</p><p>You send a notification, then a second, then a third. Everything works fine. However, when sending the fourth, everything breaks.</p><p>Well, the good news is that it’s fairly easy to fix!</p><p>TL;DR: It’s a problem with your push implementation.</p><p>Of course, push subscriptions are never automatically terminated when implemented correctly. This would defeat the whole purpose of the feature!</p><p><em>(Side note: if you don’t want to bother with these boring technical implementation details, go ahead and sign up for </em><a href="https://progressier.com/"><em>Progressier</em></a><em> instead).</em></p><h3>How to fix push subscriptions being terminated on iOS Safari</h3><p>When you send a push notification to a subscribed user, the service worker for the matching domain fires a push event. The <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushEvent">push event handler</a> in your service worker is responsible for showing the notification to the user.</p><p>However, one very important detail that many implementations are missing is that <strong>your event handler must absolutely show the notification before the event itself terminates.</strong></p><p>Notifications are displayed using <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification">registration.showNotification()</a>. This function returns a Promise that resolves once the notification has been shown to the user.</p><p>Almost all cases of push subscriptions being terminated by Safari can be explained by push event handlers missing <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil">event.waitUntil()</a>. This is a common issue. Even the <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushEvent">sample code on MDN</a> contains that problem:</p><p>❌ Incorrect:</p><pre>self.addEventListener(&quot;push&quot;, function(e){ <br>  self.registration.showNotification(e.data.title, e.data); <br>});</pre><p>If you use the sample code above, push notifications won’t work properly in the long run on iOS because the promise returned by <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification">registration.showNotification()</a> will often resolve after the push event handler has finished.</p><p>❌ Also incorrect:</p><pre>self.addEventListener(&quot;push&quot;, async function(e){ <br>  await self.registration.showNotification(e.data.title, e.data); <br>});</pre><p>Making the event listener asynchronous and awaiting the <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification">registration.showNotification()</a> promise to resolve looks like a very tempting solution. But you’ll still run into the same issues.</p><p>Here is why: it’s not enough for your event <em>handler</em> to wait for the work to be finished. You have to proactively tell the service worker what the <em>event itself</em> requires to be considered finished. This is counterintuitive because you rarely (if ever?) see that sort of behavior anywhere in client-side or server-side logic.</p><pre>self.addEventListener(&quot;push&quot;, function(e){ <br>  event.waitUntil( <br>    self.registration.showNotification(e.data.title, e.data) <br>  ); <br>});</pre><p>This is a simplified example. In most cases, your code will do a few other things before invoking <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification">registration.showNotification()</a>. Just remember to wrap that last bit in <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil">event.waitUntil()</a> and remember that <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil">event.waitUntil()</a> expects a Promise (not a function) as an argument.</p><h3>So why are push notifications working in other browsers if my implementation is faulty?</h3><p>This is because of a concept called <em>silent push</em>. A <em>silent push</em> occurs when the browser receives a notification but fails to display it to the user (or does so with a delay).</p><p>When you omit <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil">event.waitUntil()</a>, Safari considers the notification to be a <em>silent push</em> because the event terminates before the notification is displayed (even if it is shown shortly thereafter).</p><p>Silent push has always been frowned upon across the board. In fact, when you <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe">register a push subscription</a>, all browsers require you to configure it as <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushSubscriptionOptions/userVisibleOnly">userVisibleOnly</a>, meaning you guarantee that you will only send notifications that you will actually show to users.</p><p>This is a security measure to prevent apps to do work in the background without users knowing about it. If you accidentally do 3 of those on Safari, the push subscription is canceled. Any further attempts would result in errors.</p><p>Other browsers have a different way of handling this. For example, Chrome does not invalidate push subscriptions, so as long as you call <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification">registration.showNotification()</a> before the event handler terminates, you’ll likely bypass Chrome’s <em>anti-silent-push</em> security measure (which is to show a default <a href="https://web.dev/push-notifications-handling-messages/"><em>This site has been updated in the background</em></a> notification).</p><p>What seemed to work in many apps for years was always wrong. Many developers are claiming Apple released a bad push implementation — but this is not what’s happening here. Apple’s implementation is arguably closer to the <a href="https://www.w3.org/TR/push-api/">W3C specs</a> than Google’s. If your setup worked in other browsers, it’s essentially because… you were able to avoid the issue by chance. In any case, implement <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil">event.waitUntil()</a> properly now. You’ll eliminate timing randomness and make your implementation more future-proof.</p><p>That’s it for me! Hopefully, now you know how to get around push subscriptions being canceled after 3 push notifications. If you have any questions, feel free to contact me <a href="https://progressier.com/">here</a>.</p><p><em>Originally published at </em><a href="https://dev.to/progressier/how-to-fix-ios-push-subscriptions-being-terminated-after-3-notifications-39a7"><em>https://dev.to</em></a><em> on June 30, 2023.</em></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b9ca186aaa" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-fix-ios-push-subscriptions-getting-terminated-after-3-notifications-26b9ca186aaa">How to fix iOS push subscriptions getting terminated after 3 notifications</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending push notifications with Safari 16 on macOS Ventura]]></title>
            <link>https://kevinbasset.medium.com/sending-push-notifications-with-safari-16-on-macos-ventura-f099dc0e7274?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/f099dc0e7274</guid>
            <category><![CDATA[safari]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[push-notification]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 00:28:55 GMT</pubDate>
            <atom:updated>2023-03-08T12:41:29.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0IpezX48MW2fB6BcrMEgw.png" /></figure><p>Good news for developers using <strong>Safari 16 on macOS Ventura</strong>: you can now send web push notifications directly through Safari 16 without the need for a <a href="http://paid Apple Developer Account">paid Apple Developer Account</a> or a custom .P12 certificate.</p><p><strong>Safari 16 on macOS Ventura</strong> now directly supports the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Web Push API</a>!</p><p>This is a major win for developers, as it shows Apple’s (new?) commitment to following <a href="https://www.w3.org/TR/push-api/">W3C specifications</a>. But don’t get too excited just yet — there are still a few things to watch out for to ensure everything runs smoothly. This article will fill you in on all the details.</p><h3>Detecting Safari</h3><p>To detect if a device is using Safari, you probably used the navigator.userAgent JavaScript property. This property returns a string that represents the user agent of the browser.</p><p>Before this new update, at <a href="https://progressier.com/">Progressier</a>, I would use the code below to detect Safari. Because I knew Safari didn’t support web push notifications, I could simply update my UI and logic accordingly.</p><pre>if (navigator.userAgent.indexOf(&#39;Safari&#39;) !== -1 &amp;&amp; navigator.userAgent.indexOf(&#39;Chrome&#39;) === -1) {<br>  // the device is using Safari<br>} else {<br>  // the device is not using Safari<br>}</pre><h3>Detecting Compatibility with the Web Push API</h3><p>However, now that all devices running <strong>Safari 16 on macOS Ventura</strong> or higher support the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Web Push API</a>, we need a new method that checks whether the device is <em>actually compatible</em> with that API.</p><p>In other words, instead of relying on <strong>browser detection</strong>, you must now switch to <strong>feature detection</strong> to ensure you prompt users that have a compatible browser to allow push notifications when required.</p><pre>if (navigator.serviceWorker &amp;&amp; window.PushManager &amp;&amp; window.Notification) {<br>  // the device supports the Web Push API<br>} else {<br>  // the device does not support the Web Push API<br>}</pre><p>This is what the code snippet above does:</p><ul><li>navigator.serviceWorker checks that the device has support for <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API">Service Workers</a>, which is a required part of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Web Push API</a>.</li><li>window.PushManager verifies that the device has support for the <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushManager">PushManager</a> interface, which is also a required part of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Web Push API</a>.</li><li>And last but not least, window.Notification ensures that the device has support for the <a href="https://developer.mozilla.org/en-US/docs/Web/API/notification">Notification API</a>.</li></ul><p>If a user’s browser supports all three, then you should be able to send push notifications to them.</p><h3>User action required</h3><p>One of the main differences between Apple’s implementation and that of the rest of the browser vendors is that you must wait for a <em>user gesture</em> (= a click) to trigger the push prompt.</p><p>If you attempt to ask users to allow push notifications outside of a click <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener">event listener</a>, this is what you’ll get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XldXbtBcJBDyut-s9mxIFQ.jpeg" /><figcaption>No prompt will be shown if you programmatically request users to allow push notifications outside a click event listener</figcaption></figure><p>If anything, that’s a good thing. I’m sure you’ve stumbled upon one of those annoying news websites asking you to allow notifications as soon as the page has fully loaded. Everybody hates those. Well, on Safari 16, they‘re not able to do that.</p><p>Even if you use push notifications properly, you may need to update your setup if you didn’t previously ask users to allow notifications from within a click event listener. I personally didn’t, and I’m guessing that most developers probably didn’t either.</p><p>Here is an example of how you might request permission to send push notifications from within a click handler in JavaScript:</p><pre>document.getElementById(&#39;myButton&#39;).addEventListener(&#39;click&#39;, function() {<br>  // Check if push notifications are supported and allowed<br>  if (navigator.serviceWorker &amp;&amp; window.PushManager &amp;&amp; window.Notification) {<br>    // Request permission to send push notifications<br>    navigator.serviceWorker.getRegistration().then(function(registration) {<br>      registration.pushManager.subscribe({ userVisibleOnly: true }).then(function(subscription) {<br>        console.log(&#39;Push notifications are allowed.&#39;);<br>        //save the push subscription in your database<br>      }).catch(function(error) {<br>        console.log(&#39;Error:&#39;, error);<br>      });<br>    });<br>  }<br>});</pre><p>At <a href="https://progressier.com/">Progressier</a>, I designed a <em>Push Button</em> that takes care of the whole logic for you:</p><ul><li>it‘s greyed out on devices that don’t support the Web Push API</li><li>it saves the push subscription in your database against their user profile (so you can sync user emails with their push subscriptions for example)</li><li>the wording of the button is updated after the user has allowed or blocked push notifications</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*13GSbffQcHbmgCRGkx8MzQ.gif" /><figcaption>Your button to request notifications should sync with the actual status of push notifications in the browser</figcaption></figure><h3>Tell users how to update their preferences after allowing/blocking notifications</h3><p>You should also tell users how they can update their notifications status. Not everyone knows the functionality can be accessed by clicking on the padlock icon in the URL bar (and in some browsers — that’s in fact not where permissions are).</p><p>Also, in the case the user has accidentally allowed or blocked notifications, you should walk them through the process of changing their preferences.</p><h4>Updating push preferences on Chrome</h4><p>For example, when a user clicks the <a href="https://progressier.com/">Progressier</a> <em>Subscribe Button</em> after they’ve blocked notifications, it shows them how to allow notifications again.</p><p>This is useful because you can’t programmatically trigger the push prompt again once they’ve blocked notifications (also a blessing — just imagine all the spam prompts we’d get otherwise).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Fy0d1gVqF3rd9GH87oGzA.gif" /></figure><h4>Updating push preferences on Safari 16+</h4><p>On Safari, the little padlock icon in the URL bar does not allow you to change your push notification preferences. So your UI must show a different set of instructions depending on whether the user browses your app using Chrome or Safari (use the method above to detect Safari).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdCDsYOmQ7bgbcBEsmQG0A.gif" /></figure><p>To update your push preferences on Safari 16, you must go to <em>Safari </em>&gt; <em>Settings </em>&gt; <em>Websites</em>. Then scroll to <em>Notifications </em>in the <em>General </em>tab<em>. </em>In the right-hand panel, you’ll see a list of domains for which you’ve allowed or blocked notifications. Use the toggle to update it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvjB87kQikNizn5-XFHcpA.png" /></figure><h3>Conclusion</h3><p>Apple finally following the W3C specs is awesome news for the web. Their implementation is very close to that of Chrome, Firefox, and Edge with only a few differences:</p><ol><li><strong>Switch to feature detection</strong> instead of browser/device detection (which will also prepare you for notifications <a href="https://javascript.plainenglish.io/everything-you-need-to-know-about-web-push-on-ios-macos-5a4b3b715b24">coming to iOS in 2023</a>).</li><li><strong>Wait for a user action</strong> to prompt your users to allow push notifications (or they won’t be prompted at all on Safari).</li><li><strong>Tell users how to update their preferences</strong> in Safari after they’ve allowed or blocked notifications</li></ol><p>If you have comments or questions, reply below or hit me up at <a href="https://progressier.com/">Progressier</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f099dc0e7274" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why haven’t PWAs killed native apps yet?]]></title>
            <link>https://kevinbasset.medium.com/why-havent-pwas-killed-native-apps-yet-29beca4425fa?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/29beca4425fa</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[no-code]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 01:18:11 GMT</pubDate>
            <atom:updated>2022-09-08T02:41:19.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7t_0PITuquU7MO4UsBAdLw.jpeg" /><figcaption>The base image was <a href="https://labs.openai.com/s/nNiRsjkZsnfuwOD0tverNlWw">generated by Dall-E</a> with the following prompt: “a 3D render of two personified smartphones fighting in a war with knives in a post-apocalyptic neon landscape”</figcaption></figure><blockquote>Kevin Basset is the Founder at <a href="https://progressier.com/?ref=m09">Progressier</a>, a software toolkit used by 5,000+ apps to emancipate themselves from the app stores.</blockquote><p>On paper, PWAs are the perfect alternative to native apps: only one code base to manage, instant updates that require no approval, and no commissions to pay on in-app purchases. What’s not to like?</p><p>Although <em>Progressive Web Apps</em> have gone a long way since their inception, they’re not quite at the point where they can act as a perfect replacement for native apps.</p><p>So… what is still missing in 2022? Why haven’t they become the default format for apps<em> </em>just yet?</p><h3>The PWA identity problem</h3><p>I’ve written about this <a href="https://javascript.plainenglish.io/i-solved-the-biggest-problem-with-pwas-2996d02c5728">specific topic in more details</a>, but PWAs still suffer from their reputation of being second-rate apps — or worse, in some cases, of not being apps <em>at all</em>.</p><p>In 2022, the default behavior is still to go look for apps on either Google Play or the App Store. Funnily enough, installing an app directly from a website is both faster and more convenient. But users still aren’t accustomed to this without dedicated <a href="https://progressier.com/features/in-app-pwa-promotion?ref=m09">prompts and promotion elements</a>.</p><p>At the core of the problem is the question of trust. Downloading an app from a third party means that the third party in question (Google or Apple) attests that the app is safe to download.</p><p>But here is the thing: PWAs don’t need Google and Apple‘s approval… because they’re already guaranteed to be secure — by design. A PWA can’t read your phone’s contacts, send SMS on your behalf, or access any of your phone’s features that could expose your private information.</p><p>The value proposition of an “app store” is twofold: <em>logistics</em> (installing your app on the user’s device) and <em>promotion</em> (getting more people to discover your app). Arguably, app stores no longer do such a great job at the latter. And the logistic of installing PWAs is embedded within the browser itself.</p><p>In 2022, the whole <em>app store paradigm</em> is redundant.</p><h3>iOS push notifications</h3><h3>Jen Simmons on Twitter: &quot;Web Push is coming to Safari 16 on macOS Ventura. It sends notifications even if Safari is closed. Is built with the same web technologies as other browsers. Doesn&#39;t require an Apple Developer Program membership. And is coming to iOS and iPadOS next year.https://t.co/XLX9oNtHWP pic.twitter.com/QqA6zniEQe / Twitter&quot;</h3><p>Web Push is coming to Safari 16 on macOS Ventura. It sends notifications even if Safari is closed. Is built with the same web technologies as other browsers. Doesn&#39;t require an Apple Developer Program membership. And is coming to iOS and iPadOS next year.https://t.co/XLX9oNtHWP pic.twitter.com/QqA6zniEQe</p><p>After many years of seemingly hopeless wait, Apple <a href="https://kevinbasset.medium.com/everything-you-need-to-know-about-web-push-on-ios-macos-5a4b3b715b24">has finally announced</a> that push notifications will be coming to iOS in 2023. This is great news. Until now, you could send notifications to your Android/Windows/macOS users, but not to your iOS users.</p><p>For many developers, this meant that it wasn’t possible to rely on push notifications completely to deliver important information to their users. Web push notifications were a nice added bonus — not a crucial part of a product‘s workflows.</p><p>Provided that Apple implements web push notifications the right way (as in, following the <a href="https://www.w3.org/TR/push-api/">W3 specs</a>), this is about to change. You’ll be able to notify users on both Android and iOS with very little effort — and without having to list your apps on Google Play and the App Store.</p><p>That being said, web developers have abused the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Web Push API</a> so much (e.g. news websites requesting access on your first visit) that people have grown to detest these prompts. As a result, in some cases, Chrome (and other browsers) <a href="https://www.searchenginejournal.com/chrome-push-notification-blocker/342593/">auto-blocks push notification requests</a> — making it harder for developers with legitimate use cases to request access to this feature.</p><p>One of the top items on my personal wishlist would be for PWAs to be granted a <em>higher authority </em>than a regular website, once installed (but not quite as much as a native app). Getting people to install your PWA is evidence that they sort of trust it — they haven’t just stumbled upon your site.</p><p>A few examples of what <em>higher authority</em> could translate into:</p><ul><li>Installed PWAs could automatically be granted access to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Push API</a>.</li><li>Restrict access to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Push API</a> to installed PWAs. Regular websites wouldn’t be allowed to request access at all. Goodbye BS spam.</li><li>Bundle requests to multiple browser APIs within the <a href="https://web.dev/learn/pwa/installation-prompt/">installation prompt</a>. For example, when installed, a PWA could request to get automatic access to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Push API</a>, the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API">Geolocation API</a>, or the <a href="https://webaudioapi.com/samples/microphone/">Microphone API</a> — with toggles for users to granularly allow or disallow each individually.</li><li>Or more modestly, Chrome could simply <em>not</em> auto-block push notifications when requested from within a PWA.</li></ul><h3>Native install prompt on iOS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7B20kY28URXyM3qChpiKg.png" /><figcaption>Installing a PWA on iOS requires showing users custom instructions</figcaption></figure><p>Installing an app on iOS currently requires opening the Share panel and clicking on the <em>Add to Home Screen</em> button. This mostly does the job, but it isn’t as straightforward as installing a native iOS app.</p><p>If Safari implemented support for the <a href="https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent">beforeInstallPrompt event</a>, the experience would be streamlined. Or at the very least, Apple could change the wording of <em>Add to Home Screen</em> to <em>Install the app</em> — Android has done exactly that a few years ago.</p><p>Although the current flow is an okay-ish workaround, it does have some unintended consequences that are detrimental to the experience for both users and developers.</p><p>For example, it’s <a href="https://www.reddit.com/r/PWA/comments/wnvijd/why_does_sfsafariviewcontroller_have_no_add_to/">impossible to distinguish</a> between actual Safari (which has an <em>Add to Home Screen</em> button) and a <a href="https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller">SFSafariViewController</a> view (which does not). For the record, the latter is used by a number of in-app browsers, e.g. the Twitter iOS app.</p><p>As a result, you have no choice but show your custom instructions… even when the option isn’t there. A tad confusing for users who may not be into that sort of technical nitpicking, aka 99.99% of users.</p><p>Similarly, I’m looking forward to the day when PWA developers no longer need to <a href="https://progressier.com/pwa-icons-and-ios-splash-screen-generator">generate 25+ individual splash screen image files</a> just to support every iPhone and iPad.</p><h3>Better post-install manifest updates</h3><p>PWAs would also become a lot more competitive if the developer was able to update the key details of the manifest (icon, name, splash screens, etc) after installation.</p><p>Google has a <a href="https://web.dev/manifest-updates/">whole article about this</a>, but I’ll give you the TL;DR: none of the properties you<em> actually</em> want to change can be changed. So once it’s installed, you can’t update how it looks on the user’s home screen.</p><p>Or at least, that was the case until very recently.</p><p>Luckily, there’s been some interesting developments in that area. Now, desktop Chrome supports changing the name of an app after it’s been installed. It even comes with a nice — albeit confusing — anti-phishing prompt so users can approve the change or uninstall the app.</p><h3>Maximiliano Firtman on Twitter: &quot;Is this a new Chrome behavior for desktop installed PWAs? I guess that it may happen when the manifest change and Chrome tries to update the installed icon to reduce phishing attempts, but I&#39;m not sure. Even if that&#39;s the case, it doesn&#39;t seem right for this case anyway. https://t.co/QNTPZGnIO3 / Twitter&quot;</h3><p>Is this a new Chrome behavior for desktop installed PWAs? I guess that it may happen when the manifest change and Chrome tries to update the installed icon to reduce phishing attempts, but I&#39;m not sure. Even if that&#39;s the case, it doesn&#39;t seem right for this case anyway. https://t.co/QNTPZGnIO3</p><h3>🦑 meduz&#39; on Twitter: &quot;Google Maps #PWA (installed using Chrome) prompts me for a &quot;app name verification&quot; (first time I see this screen), but the name hasn&#39;t changed. 🤔I can either validate (OK) or uninstall the app (&quot; Désinstaller l&#39;appli &quot;, in French). pic.twitter.com/YLCa9wljpI / Twitter&quot;</h3><p>Google Maps #PWA (installed using Chrome) prompts me for a &quot;app name verification&quot; (first time I see this screen), but the name hasn&#39;t changed. 🤔I can either validate (OK) or uninstall the app (&quot; Désinstaller l&#39;appli &quot;, in French). pic.twitter.com/YLCa9wljpI</p><h3>Better scope management</h3><p>If there’s one area where PWAs really shine is <a href="https://progressier.com/features/programmatic-pwa-creation?ref=m09">programmatic app creation.</a></p><p>One of my customers at <a href="https://progressier.com/?ref=m09">Progressier</a> is a company that commercializes software for photographers. Photographers use that software to create unique wedding galleries for their own customers.</p><p>With <a href="https://progressier.com/?ref=m09">Progressier</a>, each of these galleries is a unique app with its own name (the name of the newlyweds) and icon (a photo of the couple). With 10,000s of such galleries, this would simply be impossible to manage any other way.</p><p>It doesn’t come without a few bottlenecks and gotchas, however.</p><p>While it’s generally preferable to host each PWA on <a href="https://web.dev/building-multiple-pwas-on-the-same-domain/">their own subdomain</a> (e.g. pwa1.example.com and pwa2.example.com), it’s often not possible. In this case, the second best option is to host each in its own directory (e.g. example.com/pwa1/ and example.com/pwa2/).</p><p>Managing scopes is very counter-intuitive because of what I like to call <em>the trailing slash problem</em>. In a nutshell, example.com/pwa1/ is a valid scope while example.com/pwa1 (notice the missing trailing slash) is not.</p><p>If you use the latter, browsers will instead consider the scope to be example.com/ (the root domain) — the problem is that there is no error message or warning. It just silently fails.</p><p>I wish browsers would be a tiny bit smarter and would automatically handle trailing slashes in the scope field. They could just auto-correct example.com/pwa1 to example.com/pwa1/. I don’t see any use cases where the former is not an error where the dev actually meant the latter.</p><p>Scopes could also be improved on iOS. Opening a link that’s within the scope of a PWA from a third-party app on Android opens the installed PWA. However, on iOS, it opens Safari instead.</p><h3>Desktop screenshots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwYnPd6uOjDO7MwDdcQqKQ.jpeg" /><figcaption>Old install prompt (left and middle) vs new install prompt (right)</figcaption></figure><p>The <a href="https://developer.chrome.com/blog/richer-pwa-installation/">Richer Installation UI</a> has definitely helped bridge the gap between native apps and PWAs. By including screenshots in the installation prompt, developers can show their app in action — and it looks and feels like a standard app store interface.</p><p>At <a href="https://progressier.com/?ref=m09">Progressier</a>, I went a bit further by providing a <a href="https://progressier.com/pwa-screenshots-generator">free tool for designing these screenshots</a> in addition to integrating the tool into the product itself. So if you’re a <a href="https://progressier.com/?ref=m09">Progressier</a> customer, you can design, manage, edit, localize, and upload your screenshots within one interface. Kinda like <em>Photoshop meets Google Play</em>.</p><p>The screenshots property of the app manifest doesn’t currently do anything on desktop — but there is an active proposal to also display these screenshots on desktop Chrome. You can already test this by using the<strong>--enable-features=DesktopPWAsDetailedInstallDialog</strong> command line flag.</p><h3>Alexey Rodionov on Twitter: &quot;Remember my proposal for adding description and screenshots from web app manifest to the PWA install UI on desktop?You can enable the new PWA install UI using --enable-features=DesktopPWAsDetailedInstallDialog command line flag. 🥳#PWA #ProgressiveWebApps #Installability #UX https://t.co/2J4N6nb9iq pic.twitter.com/hpdMy2DOtj / Twitter&quot;</h3><p>Remember my proposal for adding description and screenshots from web app manifest to the PWA install UI on desktop?You can enable the new PWA install UI using --enable-features=DesktopPWAsDetailedInstallDialog command line flag. 🥳#PWA #ProgressiveWebApps #Installability #UX https://t.co/2J4N6nb9iq pic.twitter.com/hpdMy2DOtj</p><h3>What about native features?</h3><p>Should PWAs ever be able to <a href="https://developer.android.com/training/contacts-provider/retrieve-names">access your contacts</a>? <a href="https://developer.android.com/guide/topics/providers/calendar-provider">view your calendar</a>? <a href="https://developer.android.com/reference/android/telephony/SmsManager">send SMS/MMS</a>? <a href="https://developer.android.com/training/scheduling/alarms">set alarms</a>? Personally, I would argue that they shouldn’t — <em>ever</em>.</p><p>The fact that PWAs are limited in their scope is the very reason why they are secure. Bypassing the browser limitations would set a dangerous precedent that would create an artificial need for a <em>third-party approver (</em>i.e. an app store<em>) </em>hence invalidating the whole concept.</p><p>Of course, some apps do need access to these features. And for those, native is — and hopefully always will be — the only way to go.</p><p>But for the vast majority of apps that do not need access to these features, PWAs can not only be a great alternative —they’re increasingly becoming the best option.</p><p>When you consider the fact that more apps get built with <a href="https://bubble.io/">Bubble</a>, <a href="https://softr.io/">Softr</a>, and other no-code platforms every day, it looks like this is the direction we’re headed.</p><p>And personally, I think this is awesome news for developers, users, and the web, as a whole.</p><blockquote>Kevin Basset is the Founder at <a href="https://progressier.com/?ref=m09">Progressier</a>, a software toolkit used by 5,000+ apps to emancipate themselves from the app stores.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29beca4425fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Stripe manages 650+ localized versions of their marketing site]]></title>
            <link>https://javascript.plainenglish.io/why-stripe-uses-invalid-alternate-seo-tags-on-their-website-237368405b60?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/237368405b60</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[seo-tips]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Sat, 20 Aug 2022 04:40:39 GMT</pubDate>
            <atom:updated>2022-12-02T00:38:08.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzWe1PZ03dMLxeib5axiCQ.jpeg" /></figure><blockquote>Kevin Basset is the Founder at <a href="https://progressier.com/">Progressier</a>, a software toolkit used by 5,000+ apps to emancipate themselves from the app stores.</blockquote><p>I came across a post on <a href="https://www.linkedin.com/posts/adityaaman_seo-hreflang-internationalseo-activity-6966377876782743553-n1CA?utm_source=linkedin_share&amp;utm_medium=member_desktop_web">LinkedIn</a> and another on <a href="https://twitter.com/yvoschaap/status/1458093647350616071">Twitter</a> pointing out that Stripe uses invalid hreflang tags to specify alternate versions of their site in other languages.</p><p>This got me curious, so I decided to look into this.</p><p>And I fell into a rabbit hole.</p><p>As it turns out… doing things the <em>wrong way</em> sometimes <em>is</em> <em>the right decision.</em></p><h3>Invalid hreflangs?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*_OsFc4WxknfdPYXNngD6oQ.jpeg" /><figcaption>32% of Stripe’s 600+ alternate tags are technically invalid</figcaption></figure><p>The job of an <a href="https://www.w3c.org.il/en/alternate-tag">alternate tag</a> is to tell search engines that the page exists in a different version better suited to a different language/country. So when someone with a browser set to pt-BR tries to access a page in English with amounts in US Dollars, Google will do its best to instead suggest the page in Portuguese with amounts in Brazilian Real.</p><p><a href="https://developers.google.com/search/docs/advanced/crawling/localized-versions#language-codes">Google’s guidelines</a> state that thehreflang attribute should contain a language code in <a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a> format (for example fr for French), and optionally a region in <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 Alpha 2</a> format (for example CA for Canada). When you combine them, you get fr-CA (French speakers in Canada).</p><p>You can do this with any combination of language and region. There are probably not many Thai speakers in Cyprus, but th-CY is still a valid hreflang. And Stripe has a dedicated page for them: <a href="https://stripe.com/th-cy">https://stripe.com/th-cy</a></p><p>However, hreflang with two region identifiers such as en-gb-BG are invalid. GB is a region identifier for the United Kingdom while BG is a region identifier for Bulgaria.</p><p>So why does Stripe do this? They should know better, shouldn’t they?</p><h3>How Stripe generate language tags</h3><p>If you scroll to the bottom of the Stripe site, you’ll see they support 44 countries and 15 languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90kDRJYWwUzh2CSRDVadCA.png" /></figure><p>Stripe has two lists, one with the languages, and another with the countries. They simply combine the two to generate each tag.</p><p>They take each language code, then append each possibly country code after it. For example:</p><ul><li>Deutsch (de) + Canada (CA) = <a href="https://stripe.com/de-ca">https://stripe.com/de-ca</a></li><li>Italiano (it) + Romania (RO) = <a href="https://stripe.com/it-ro">https://stripe.com/it-ro</a></li><li>French (fr) + Japan (JP) = <a href="https://stripe.com/fr-jp">https://stripe.com/fr-jp</a></li></ul><p>When you access the Stripe website, their server has a function that automatically creates these meta tags and appends them to the &lt;head&gt; of the HTML that’s returned to the browser.</p><p>There’s no way this is done manually. When Stripe adds support for a new language and/or country, this automatically creates a whole bunch of new versions of the site. Programmatic SEO at its best.</p><p>And currently, there are quite a few versions of the site. 44 countries * 15 languages = 660 localized versions of the Stripe site.</p><h3>The root cause</h3><p>The problem is that some of the languages in the list are already complete language codes. English (United Kingdom) is en-GB and French (Canada) is fr-CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*CHdf_23m16pfzB2lab1QFQ.png" /></figure><p>So when you combine them with each country from your country list, you get new weird-looking codes:</p><ul><li>English (UK) (en-GB) + Germany (de) = <a href="https://stripe.com/en-gb-de">https://stripe.com/en-gb-de</a></li><li>Portuguese (Brazil) (pt-BR) + Austria (AT) = <a href="https://stripe.com/pt-br-at">https://stripe.com/pt-br-at</a></li><li>Español (América Latina) (en-419) + Cyprus (CY) = <a href="https://stripe.com/es-419-cy">https://stripe.com/es-419-cy</a></li></ul><p>These last three are technically invalid… but only from an SEO hreflang perspective. Nothing prevents Stripe from having a version of their site for Portuguese speakers from Brazil currently in Austria.</p><p>In fact, I’d argue that it’s a <em>very good implementation</em>. Many websites tie the language/currency/country together in a single selection menu. As a native French speaker living in Taiwan, I personally hate this. I want to see the amounts in TWD because after ten years here, that’s the currency I’m the most accustomed to. But I cannot really read Chinese very well, so I’d rather see the content in English or my native French.</p><p>Stripe lets you choose <em>any currency </em>(by choosing a country)<em> </em>and combine it with any <em>language</em>. There aren’t so many non-e-commerce sites that do this. And this is brilliant.</p><h3>Invalid… so what?</h3><p>Anyway, even if all the hreflang with two hyphens on the Stripe website are invalid, it begs the question… why does it matter?</p><p>I’m not 100% sure what the consequence is SEO-wise. But if I had to guess, I would say search engines probably just ignore each alternate link that has a hreflang parameter it deems invalid.</p><p>Interestingly, if you run Lighthouse on one of those pages, it does pass the “<em>Document has a valid </em><em>hreflang</em>” test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10vpyNJJU2RUDZYSsPJlhA.png" /></figure><p>So even if they’re technically invalid, it looks like Google understands them anyway. I think they likely process them in one of two ways:</p><ul><li>by trimming them (so en-gb-AE is interpreted as just en-GB or possibly en-AE)</li><li>or by correctly interpreting en-gb-AE as the alternative for users with a browser set to “<em>English (United Kingdom)</em>” located in the UAE</li></ul><p>Smart Google.</p><h3>Why doesn’t Stripe fix this?</h3><p>The seemingly easy fix would be to clean up the list of languages so that they only contain simple language codes (en, fr, etc) instead of language + country codes (en-GB, fr-CA, etc). This is what it would look like then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A4rWj5Wz4cOkTOnUHCqj9A.png" /></figure><p>You would then combine these languages with country codes, and you’d eliminate all invalid hreflang tags.</p><p>But Stripe already has a lot of pages, and a lot of dependencies I’m not aware of. It wouldn’t just be a matter of changing the hreflang attributes. You’d have to change the entire structure of a site with thousands of pages.</p><p>It wouldn’t be a simple fix.</p><p>Given that as-is, the current strategy doesn’t appear to yield any negative effects, Stripe most likely doesn’t deem it a good use of any of their engineers’ time.</p><p>Fair enough.</p><h3>But… is it actually an issue?</h3><p>Counterintuitively, there’s actually a valid reason for doing things that way. It has to do with number formatting. Check these two pages:</p><p><a href="https://stripe.com/es-419-us">https://stripe.com/es-419-us</a> (Spanish (Latin America) + United States)<br><a href="https://stripe.com/es-us">https://stripe.com/es-us</a> (Spanish (Spain) + United States)</p><p>Both have us as the region indicator, so the currency is USD. But the first part tells you how the numbers should be formatted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*A1S845trBAAAp-CpURDezw.png" /><figcaption>In Spanish from Spain, the currency symbol comes after the number, the decimal separator is a comma, and the thousands separator is a period.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*C56FASwRoW0AVk1xBK2vFw.png" /><figcaption>In Spanish from Latin America, the currency symbol comes before the number, the decimal separator is a period, and the thousands separator is a comma.</figcaption></figure><p>And this is how it should be done. Number formatting changes based on the language used, not the currency or the country.</p><p>You couldn’t do this with completely valid hreflang tags. With es-US, how would you decide if you should format currencies the Spanish or Latin American way?</p><p>Sure, I guess you could decide that es-US follows the Spanish way, and then have es-CL (Chile) and es-PE (Peru), and the rest of the codes for South America follows the Latin American way.</p><p>Or you could decide that es-US should follow the Latin American way, because it’s the same as the North American way, and statistically, there are more South/Central Americans than Spaniards in the US.</p><p>Notice what it does in both cases? It requires making decisions. It adds complexity. <em>Opinionated</em> complexity. And that’s just one example.</p><p>Besides number formatting, it’s also very likely there are differences in the wording used on both pages. But I don’t speak Spanish, so I’ll let someone else figure this out.</p><h3>Conclusion</h3><p>If you just look at the HTML of the homepage of Stripe’s website, it might look like an oversight on Stripe’s part.</p><p>If you actually dig deeper, you’ll realize it really isn’t. In fact, it isn’t even a “bug” at all. I’d be willing to bet Stripe used this approach deliberately.</p><p>Stripe’s localization strategy is one of the best I’ve seen on the web. The invalid hreflang attributes are just a small price to pay for that.</p><p>Knowing the rules is important.</p><p>Knowing when to break the rules is key.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=237368405b60" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/why-stripe-uses-invalid-alternate-seo-tags-on-their-website-237368405b60">How Stripe manages 650+ localized versions of their marketing site</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything You Need to Know About Web Push on iOS/macOS]]></title>
            <link>https://javascript.plainenglish.io/everything-you-need-to-know-about-web-push-on-ios-macos-5a4b3b715b24?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a4b3b715b24</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 12:16:08 GMT</pubDate>
            <atom:updated>2022-09-12T23:56:26.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xF_Qx7V2zBt1zgGEtUj6mQ.jpeg" /></figure><blockquote>Kevin Basset is the Founder at <a href="https://progressier.com/?ref=m09">Progressier</a>, a software toolkit used by 5,000+ apps to emancipate themselves from the app stores.</blockquote><p>Apple <a href="https://twitter.com/jensimmons/status/1533893843799748610">announced at WWDC22</a> that Web Push is finally coming to Safari. It’s already available in Safari 16 Beta on macOS. And next year, it’s coming to iOS and iPadOS as well.</p><h3>Jen Simmons on Twitter: &quot;Web Push is coming to Safari 16 on macOS Ventura. It sends notifications even if Safari is closed. Is built with the same web technologies as other browsers. Doesn&#39;t require an Apple Developer Program membership. And is coming to iOS and iPadOS next year.https://t.co/XLX9oNtHWP pic.twitter.com/QqA6zniEQe / Twitter&quot;</h3><p>Web Push is coming to Safari 16 on macOS Ventura. It sends notifications even if Safari is closed. Is built with the same web technologies as other browsers. Doesn&#39;t require an Apple Developer Program membership. And is coming to iOS and iPadOS next year.https://t.co/XLX9oNtHWP pic.twitter.com/QqA6zniEQe</p><p>Hurray! At <a href="https://progressier.com/?ref=wwdc22">Progressier</a>, iOS push notifications are by far the most requested feature of all time. And for good reasons — PWAs are an increasingly viable alternative to the standard Google Play/App Store app paradigm:</p><ul><li>A PWA requires only one code base</li><li>Updates don’t require approvals.</li><li>No hefty commissions on in-app purchases</li><li>PWAs can <a href="https://progressier.com/features/programmatic-pwa-creation">be created programmatically</a></li><li>Nobody can <a href="https://www.businessofbusiness.com/articles/so-your-app-has-been-banned-by-big-tech-now-what-Google-Apple-Facebook-suspended-appeals/">ban your PWA</a>. It lives on the free web.</li></ul><p>Push notifications were a bottleneck. Previously only available on Android, Windows, and macOS (via Chrome), the lack of support on iOS meant that there was an entire platform where it simply wasn’t possible to send notifications at all.</p><p>With added support for web push from Apple, there’s arguably not much you can do with a native app that you can’t do with a PWA.</p><h3>When will Web Push be available on Safari?</h3><p>We don’t know exactly when developers will be able to prompt the general public to allow notifications on Safari. But here is what we know:</p><ul><li>Web Push is available in <a href="https://webkit.org/blog/12824/news-from-wwdc-webkit-features-in-safari-16-beta/">Safari 16 Beta</a> on macOS Ventura. The beta is downloadable today.</li><li>Web Push will <a href="https://twitter.com/jensimmons/status/1533908770853638147">come to iOS 16 in 2023</a>.</li></ul><p>From there, we can make some educated guesses regarding general availability.</p><ul><li>Safari 15 was released on September 20, 2021.</li><li>Safari 14 was released on September 16, 2020.</li><li>Safari 13 was released on September 19, 2019.</li></ul><p>It’s probably safe to assume Safari 16 will be released publicly sometime between September 15 to September 25, 2022.</p><p>Also, so far, Web Push has only been announced for Safari on macOS Ventura. <a href="https://twitter.com/firt/status/1533898763324076033">Maximiliano Firtman asked </a>whether macOS Monterey or older macOS versions would also get access to the feature when Safari 16 is released for them. The <a href="https://twitter.com/firt/status/1533898763324076033">response</a> seems to be negative — at least for the time being.</p><p>So when will macOS Ventura be released?</p><ul><li>macOS Monterey was released on October 25, 2021.</li><li>macOS Big Sur was released on November 12, 2020.</li><li>macOS Catalina was released on October 7, 2019.</li></ul><p>So a conservative estimate for Web Push general availability on macOS is around ~November 15, 2022, once both macOS Ventura and Safari 16 are available.</p><p>iOS 16 will likely be released with Safari 16 in September 2022. However, Apple <a href="https://twitter.com/jensimmons/status/1533908770853638147">made it clear</a> that Web Push on iOS will be part of a later update (not the 16.0). There are typically <a href="https://en.wikipedia.org/wiki/IOS_version_history#iOS_16_/_iPadOS_16">monthly to bi-monthly iOS updates</a>. We don’t know which exactly will contain the push notification feature. But it will come sometime in 2023. My money is on the end of March/April 2023.</p><h3>What do you need to do to implement Web Push on iOS?</h3><p>This time, Apple appears to be following <a href="https://www.w3.org/TR/push-api/">W3C specs</a>. So there will be no need to <a href="https://twitter.com/kvnbsst/status/1533991902973861888">implement a .P12 certificate</a> as was previously the case. You won’t have to be an Apple Developer Program member to use push notifications either.</p><p>For developers, very little work should be required to make their app compatible with Web Push on iOS, iPadOS, and macOS.</p><p>However, if your push implementation has previously excluded Safari through browser detection, you’ll need to switch to feature detection to get it working. Here is an example of a JavaScript function that tells you if the current browser is compatible with push notifications:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15670676a5b0d5bdcdf4b9392a85659c/href">https://medium.com/media/15670676a5b0d5bdcdf4b9392a85659c/href</a></iframe><p>The above currently returns <strong>false</strong> on Safari and should return <strong>true</strong> on Safari 16.</p><p>Secondly, if you manage push endpoints on your server, you’ll also have to allow URLs from any subdomain of <strong>push.apple.com</strong>.</p><p><a href="https://developer.apple.com/videos/play/wwdc2022/10098">Meet Web Push for Safari - WWDC22 - Videos - Apple Developer</a></p><h3>Will PWAs be allowed to use Web Push on iOS?</h3><p>As <a href="https://twitter.com/PantchoT/status/1533978089088331776">pointed out by Arye Shalev</a>, on iOS, PWAs are isolated instances of Safari once added to a home screen. Will they still get access to the Web Push API? We don’t know yet. But if the answer ends up being “no”, there will be a few note-worthy consequences:</p><ol><li>Developers will have to implement a new flow where they ask users to allow notifications before they install their PWA — because it will not be possible to ask them once the app has been installed.</li><li>When a user clicks on a push notification, it will open Safari instead of the installed PWA.</li></ol><h3>Which push services will work with Web Push on iOS?</h3><p><a href="https://progressier.com/?ref=wwdc22a">Progressier</a> is already compatible. It’s very likely other push services such as <a href="https://onesignal.com/">OneSignal</a>, <a href="https://firebase.google.com/products/in-app-messaging/">Firebase In-App Messaging</a>, and <a href="https://pushalert.co/">PushAlert</a> will also offer support before Safari 16 and iOS 16 become generally available.</p><p>In other words, if you’re using a third-party service (and <a href="https://javascript.plainenglish.io/building-a-push-service-that-scales-to-1m-subscribers-with-firebase-958b502a2a3d">you probably should</a>), there’s nothing for you to do. But you’ll soon get a new flurry of subscribers from iOS and macOS — isn’t that nice?</p><p>Do you have any questions or feedback about the upcoming Web Push updates on iOS/macOS? Let me know in the comments.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Check out our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Community Discord</em></strong></a><em> and join our </em><a href="https://inplainenglish.pallet.com/talent/welcome"><strong><em>Talent Collective</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a4b3b715b24" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/everything-you-need-to-know-about-web-push-on-ios-macos-5a4b3b715b24">Everything You Need to Know About Web Push on iOS/macOS</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why the Wordle Acquisition is Great News for the Web]]></title>
            <link>https://javascript.plainenglish.io/why-the-wordle-acquisition-is-great-news-for-the-web-fe3d19fbb5f4?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe3d19fbb5f4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[wordle]]></category>
            <category><![CDATA[acquisition]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 07:51:42 GMT</pubDate>
            <atom:updated>2026-09-04T02:06:45.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EGyM9JYWmb8c4F67.jpeg" /></figure><p>Being the maker of <a href="https://progressier.com/">Progressier</a>, I felt like I absolutely had to write about <a href="https://www.powerlanguage.co.uk/wordle/">Wordle</a>. This little web-based game has received a disproportionate amount of attention from the media in the past 30 days — like no other web app ever before, really.</p><p>Between <a href="https://www.theguardian.com/games/2021/dec/23/what-is-wordle-the-new-viral-word-game-delighting-the-internet">Wordle going viral</a>, <a href="https://www.ign.com/articles/wordle-copycat-app-store-twitter">unscrupulous developers shamelessly banking on the idea</a>, <a href="https://www.nbcnews.com/pop-culture/viral/twitter-suspends-wordle-spoiler-bot-rcna13666">Twitter bots spoiling the game</a>, <a href="https://www.techradar.com/news/dodgy-wordle-copycats-are-already-banned-from-apples-app-store-but-theres-more-work-to-do">app stores banning the copycats</a>, and <a href="https://phandroid.com/2022/01/30/5-best-wordle-alternatives/">countless alternatives appearing left and right</a>, there’s no way you haven’t heard of it by now.</p><p>Today, in an unexpected turn of events, The New York Times <a href="https://www.nytimes.com/2022/01/31/business/media/new-york-times-wordle.html">announced they acquired Wordle</a> for a price in the “low seven figures”.</p><p>So how did this simple word game become such a phenomenon? Why did The New York Times buy it? And what does the acquisition mean for the game and the future of the web?</p><h3>Less is more</h3><p>If Wordle is so popular, it’s first and foremost because it’s a great game. In 2022, making a game with such simple mechanics so compelling is no easy feat. Simple is hard.</p><p>Most games are about getting you hooked. The longer you play, the more ads you see — or the more in-app purchases you make. With Wordle, you‘ll only play for about 5 to 10 minutes a day. Once you’ve guessed the word, you’re done for the day. Beautiful.</p><p>Scarcity creates anticipation. Anticipation creates fun. Whether this was a deliberate choice or a happy accident, Wordle owes a lot of its success to its screen-time-limiting mechanics. Anecdotally, I tried playing clones that offer unlimited plays — they’re arguably a lot less fun than the original.</p><p><a href="https://www.powerlanguage.co.uk/wordle/">Wordle - A daily word game</a></p><h3>Built-in virality</h3><p>With Wordle, everyone plays the same word at the same time. This is great because it turns an otherwise solo game into a shareable <em>play-it-together</em> experience. And social media surely loves that.</p><p>And oh, did <a href="https://www.powerlanguage.co.uk/">Josh Wardle</a> really know how to harness the power of social media. Not really surprising if you consider that he used to work at Reddit, and previously created <a href="https://www.nbcnews.com/tech/internet/reddit-button-n357841">The Button in 2015</a> and <a href="https://www.newsweek.com/reddit-place-internet-experiment-579049">Place in 2017</a>, two other online experiments with built-in virality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*kqy3ziM51QXCDJUj" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/0*hHmB3ZRgU9kEK8Bd.jpeg" /><figcaption>These cryptic tweets have surely helped make Wordle popular</figcaption></figure><p>These cryptic tweets have surely helped make Wordle popular</p><p>Let’s just take a moment to appreciate how brilliant these cryptic tweets are. They’re enigmatic enough to make you wonder what the heck is happening when seeing all your friends share them. Yet they’re not so revealing that they’ll spoil the fun for everyone else. Simply brilliant.</p><h3>When the web is done right</h3><p>Wordle is also the perfect example of what the web can offer when done right: no download, no ads, no tracking, a simple interface, a native app feel, and an app that works on every browser and device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*aiwEj3XKByy51_0B.gif" /><figcaption>Wordle animations make you forget the whole thing is actually a website — not a native app.</figcaption></figure><p>Wordle animations are simple but to the point. They make you forget the whole thing is actually a website — not a native app.</p><p>It also has a very low carbon footprint. Look at the size of the app’s network requests below. The whole game weighs practically nothing. In a world <a href="https://aremythirdpartiesgreen.com/">where 94% of websites include third-party libraries,</a> this is refreshing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VVMnB_kaw2dv8LnM.jpeg" /><figcaption>Wordle is an HTML file, a logo, two small JavaScript files, and Google Analytics, weighting less than 150Kb total</figcaption></figure><p>Wordle is an HTML file, a logo, two small JavaScript files, and Google Analytics, weighting less than 150Kb total.</p><p>I’ve seen people comment that Josh Wardle was selling the game because he couldn’t manage its traffic. Sorry, but I don’t think this is what’s happening at all. As is, hosting the whole app with its hundreds of thousands (millions?) of daily users probably costs less than $100/month.</p><p>Everything is happening in the browser. This can scale indefinitely without much work.</p><p>But let’s imagine for a moment that he had instead decided to store the word list in a database rather than hard-code it in his client-side code.</p><p>Then, every single time someone would enter a word, the app would have needed to call its server to verify it. This would have meant hundreds of API calls per user per month. This can get expensive quite quickly with AWS or GCP.</p><p>Right now, after the game is downloaded once, the browser will cache the JavaScript files. In subsequent plays, it essentially costs the developer $0.</p><p>Anyone familiar with web development knows that you don’t store anything important in the browser. <a href="https://en.wikipedia.org/wiki/Security_through_obscurity">Security through obscurity</a> doesn’t work. But given that it was just a simple game with small stakes and small ambitions, this was probably the right call. And this wouldn’t have prevented the bots from spoiling the fun anyway — they would have just found a way to ruin today’s word instead of tomorrow’s.</p><h3>So, what’s next for Wordle?</h3><p>First, I’m afraid that the very reasons that made Wordle popular (no ads, no tracking, no in-app purchases, play only once a day) might get lost in this acquisition. Although The New York Times mentioned keeping the game <em>initially</em> free to play, it definitely won’t stay that way forever.</p><p>Wordle will eventually be included in <a href="https://www.nytimes.com/subscription/games">The New York Times Game Subscription</a> — they’re obviously betting that the addition of Wordle will increase their MRR. The New York Times had revenues of $1.9 billion in 2019, so whether this acquisition achieves this goal or not, the “low seven-figure price” keeps it a small bet with small risks. No biggie.</p><p>Also, congrats to Josh Wardle for selling his game! Although I don’t think managing it as-is was particularly monetarily overwhelming, monetizing it in the future would have probably proven difficult. People play it because it’s <em>free</em> and <em>fun</em>. Remove<em> “free”</em> from the equation and you probably remove the “<em>fun”</em> as well.</p><p>In that regard, I think The New York Times was the best home for the game. They know how to monetize games without plastering them with ads. While they haven’t mentioned exactly what the acquisition entails for the game, it’s fair to expect that they’ll release a whole bunch of new features soon.</p><p>It’s likely you’ll still be able to play the game as-is for as long as you like. But new future features will be part of their subscription plan. Here are some of paid features I predict will appear soon:</p><ul><li>Play with four-, six- or seven-letter words</li><li>Play all past Wordles</li><li>Multiplayer mode</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/0*OHWyUla5PdEq-w3n.png" /><figcaption>Streaks and stats keep you playing every day</figcaption></figure><p>I’m also curious to see how they’ll manage the transition — particularly how they’ll allow users to retain their streak and stats, another important component of the appeal of Wordle.</p><p>As is, it’s all stored in the browser <a href="https://progressier.com/pwa-capabilities/localstorage-demo">localStorage</a>. Everything in there is tied to a particular domain. So there’s no way to automatically move user settings — and user streaks — from <em>powerlanguage.co.uk</em> to <em>whatever-domain-nyt-will-be-using.com.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0mZuk6oApv-ela8z.jpeg" /><figcaption>All of Wordle’s logic only exists in the browser</figcaption></figure><p>They’ll have<em> </em>to create user profiles with these client settings in a database next time users visit <em>powerlanguage.co.uk</em>, return a user ID to the browser, and from that point on, save all streaks and settings server-side against that user ID instead of locally. And at some point, that same database will be used by the New York Times domain.</p><h3>The New York Times will improve the game</h3><p>I think there’s a good chance The New York Times will genuinely take the game to the next level — improving on everything that wasn’t done quite right.</p><p>First off, Wordle definitely deserves its own domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QadZnsO5ll5q5dKw.jpeg" /><figcaption>Fun fact, wordle.com is currently for sale on GoDaddy. If you feel like making a quick buck, buy it and sell it back to the New York Times in a few weeks.</figcaption></figure><p>Fun fact, wordle.com is currently for sale on GoDaddy. If you feel like making a quick buck, buy it and sell it back to the New York Times in a few weeks.</p><p>In my opinion, Wordle deserves the designation of “<em>Progressive Web App</em>”. But from a technical perspective, it’s not. It doesn’t have a <a href="https://progressier.com/service-worker-strategy-builder">service worker</a>. With a service worker, it would have been trivial to make the game playable offline completely. And it also would have been installable on desktop.</p><p>It’s great that reporters write articles <a href="https://www.laptopmag.com/how-to/how-to-install-wordle-on-an-iphone-or-android-phone">explaining the add-to-home-screen functionality</a>. But it wouldn’t have been necessary if the developer had bothered actually promoting that option within the app. Hopefully, The New York Times will correct that!</p><p>Google and Apple have<a href="https://javascript.plainenglish.io/i-solved-the-biggest-problem-with-pwas-2996d02c5728"> conditioned us to believe that apps must be downloaded from app stores</a> or otherwise they’re “not real apps”. The truth is that websites can be apps. Wordle is for all intents and purposes, a real app.</p><p>And in 2022, this app format can be installed on one’s device — just like any other app. In fact, you could even argue that PWAs are better since they can be installed on Mac OS, Windows, Chrome OS, Android, and iOS. <em>Universal</em> availability — isn’t it great?</p><p>Despite running a company called <a href="https://progressier.com/">Progressier</a>, I’ve always disliked the “PWA” acronym. I wish we would rename this app format “<em>Universal Apps</em>” or some other term that highlights their advantages. The more-obscure “<em>progressive</em>” term really only speaks of its technical aspects — i.e. the idea that you can <em>progressively</em> enhance your web app with features, rather than add them all at once. Not very good marketing at all IMHO.</p><p>But… the makers of your app stores are also the makers of your browsers. So there’s little incentive for them to promote <em>universal apps</em>. Although — to its credit — Google does push the concept more than one could legitimately expect them to. Kudos to them for that.</p><p>Finally, kudos to Josh Wardle for helping democratize the web as a viable medium for hosting apps. Wordle is the perfect proof that a great product — especially one with built-in virality — can be loved by users regardless of its form factor or provenance.</p><p>If a 2-month old project hosted on a subdirectory of a domain as unattractive as <em>powerlanguage.co.uk </em>can lead to a million-dollar payout<em>, </em>then you got a good reason to skip uploading your app to Google Play and the App Store. And instead, simply focus your attention on building a great product.</p><p>Web3/NTF/Metaverse/{insert buzzword of the day} — the web is filled with instances of <a href="https://academic.oup.com/camqtly/article-abstract/48/3/295/5573301?redirectedFrom=fulltext"><em>style over substance</em></a><em>.</em></p><p>Let’s just appreciate that, for once, the <em>substance</em> has triumphed.</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe3d19fbb5f4" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/why-the-wordle-acquisition-is-great-news-for-the-web-fe3d19fbb5f4">Why the Wordle Acquisition is Great News for the Web</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a PWA from Scratch with Vanilla JS]]></title>
            <link>https://javascript.plainenglish.io/create-a-pwa-from-scratch-with-vanilla-javascript-c726c5b2f9e0?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/c726c5b2f9e0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 08:23:17 GMT</pubDate>
            <atom:updated>2022-01-02T02:39:24.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADLHhMXJHzeu5L0V5IkOgA.jpeg" /></figure><p>When COVID started spreading in China in January 2020, I took it upon myself to build <a href="https://progressier.com/?force=true#story">The Coronavirus App</a>. That simple PWA has since been used by more than 15 million individual users.</p><p>The problems I encountered while building that app then inspired me to create <a href="https://progressier.com/">Progressier</a>, a SaaS platform that makes it possible to add the entire block of functionality we call “Progressive Web App” to any domain without having to write any code.</p><p>In this article, I’ll share some tips and tricks about what I’ve learnt developing PWAs from scratch with Vanilla JS.</p><h3>Not so easy… but worth it</h3><p>A PWA offers a sexy promise: only one code base to manage and your app works on all platforms. In practice, that means that you have to make that one code base do a lot more things than if you developed several standalone native apps.</p><p>The pros probably outweigh the cons most of the time. But it isn’t black or white. Developers blindly promoting PWAs as a replacement for native apps simply haven’t spent enough time developing PWAs. Native apps also have their place.</p><h3>Don’t go desktop-first… nor mobile-first</h3><p>Until a decade ago, most websites were first and foremost optimized for desktop use. Then came mobile phones, and we started making websites responsive.</p><p>With PWAs, you can’t think desktop-first. And you probably shouldn’t think mobile-first either. A PWA created with Vanilla JS has to look and feel like a native app on mobile. But it also has to look like a proper desktop app on desktop.</p><p>These are two completely different UI paradigms — it’s not just about the size of elements. For example, mobile UIs tend to display only one interactive element at a time while desktop UIs usually have many of them displayed simultaneously. Here are some concrete examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-bLX5HoTs9ykoWhXhE6lGA.jpeg" /><figcaption><em>A standard dropdown menu on desktop becomes a bottom drawer with an overlay on mobile</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NNv6ByGQBmnjPYfKsrujw.jpeg" /><figcaption><em>Desktop accordion items become standalone full screen components on mobile</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KmlOBaHVb8BPUwPR56aJ7A.jpeg" /><figcaption><em>A side panel searchable list on desktop becomes a mobile search bar</em></figcaption></figure><p>As a rule of thumb, create one single HTML element and use CSS to style it. Often that will mean changing the element position from relative to fixed or absolute.</p><p>Sometimes, it isn’t really possible. When developing a PWA with Vanilla JS, it’s not uncommon to run into z-index issues. An element has to appear on top of a sibling of their parent container when it&#39;s open on mobile, while the parent has to appear underneath the sibling when it&#39;s not. When that happens, you&#39;ll have to implement a few tricks to modify the z-index of the parent dynamically with JavaScript.</p><p>When you design components for a PWA, start with the functionality, then design their mobile and desktop versions concurrently. And only then figure out what the right HTML structure should be.</p><h3>Abstract away</h3><p>Proponents of frameworks like React or Vue sometimes argue that Vanilla JS is too verbose and inefficient. They also argue that if you solve that by abstracting the browser APIs, you’re essentially creating your own framework (aka “reinventing the wheel”). Below are two code snippets that do the exact same thing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea508d65d8f2afbfbd3460fc91e915e6/href">https://medium.com/media/ea508d65d8f2afbfbd3460fc91e915e6/href</a></iframe><p>The benefits of my homemade abstraction are pretty obvious. 61 characters instead of 139 means you save time typing code and the browser saves time getting it from your server. Each HTML element being one line, your code also becomes easier to read and organize.</p><p>Yet both functions are semantically identical. They both create a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Node">DOM Node</a>, add a class and an event listener to it, and append it to the DOM. Vanilla JS is about using the default browser APIs. Frameworks, on the other hand, are opinionated. They introduce their own preconceptions about how things should be done. Think how <a href="https://reactjs.org/docs/introducing-jsx.html">React uses JXS to create a hybrid HTML/JavaScript declarative style</a> for example. Frameworks create different paradigms. Shortening the syntax of Vanilla JS doesn’t fall into that category, in my humble opinion.</p><p>Ten years ago, jQuery was popular because it made things more consistent across browsers. Nowadays, most browser APIs are so well-built and documented that you probably don’t need anything else. Another good example is <a href="https://momentjs.com/">Moment.js</a> — dealing with dates and time used to be a pain in the ass. Now with the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date()</a> interface, it’s easy. And it’s available in JavaScript.</p><p>So use Vanilla JS but build your own abstractions. Make it as simple as possible to write, understand, organize and modify your code. You’re definitely going to need to be organized to make a PWA created from scratch with Vanilla JS work on all the platforms it has to support.</p><h3>Design reusable components</h3><p>Without a framework structuring your code for you, you have to be extra careful not to turn your project into spaghetti code. What has worked well for me is creating semantic silos/components. One component is a JavaScript function that contains everything that pertains to that component: the HTML, DOM nodes, event listeners, CSS, logic are all in the same place.</p><p>In addition to making your code more readable, it also makes it easier to iterate on your product. When you have to delete a component, you just remove the entire block of code. You can be sure it won’t break anything else, and your codebase never contains leftovers from previous iterations.</p><p>You don’t really need to use frameworks to build components. In fact, you’d be surprised how easy it really is with Vanilla JS. And you don’t even need the fancy <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class">class</a> declaration either. Below is my basic structure for creating components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fad8bd61f5d451415e08de4ffae9b74d/href">https://medium.com/media/fad8bd61f5d451415e08de4ffae9b74d/href</a></iframe><p>I can’t recall ever needing more than that. It really does everything you might want it to do: create custom CSS, create a container, lets you wait for data from the network if needed, lets you re-render the container when data changes.</p><p>And because you’re using Vanilla JS, you can structure each component slightly differently. For example, a different component may not be self-initializing like the one above. Or it may be invoked with completely different parameters, say data from another component.</p><p>Of course, there are probably a thousand other ways you could go about this that would work equally well.</p><h3>Use the right tools for the job</h3><h4><strong>Recommendation 1: Use libraries</strong></h4><p>Using Vanilla JS doesn’t mean you can’t utilize libraries that abstract some complex things that aren’t available straight out of the box in the browser. The key is that these libraries should work in their own silo and not force you to rewrite your entire app around them. For example, don’t build your own maps — use <a href="https://leafletjs.com/">Leaflet.js</a>. And don’t build your own charts — instead, use <a href="https://www.chartjs.org/">Charts.js</a>.</p><h4>Recommendation 2: <a href="https://www.browserstack.com/">BrowserStack</a></h4><p>You’re going to have to spend a substantial amount of time testing your PWA in different browsers. Personally, I’m a big fan of Browserstack. The platform allows you to test any web app or website on every browser/OS combination imaginable — even older devices. And these are real devices, not emulated devices. The $39 I pay every month for it is well worth it. I’m not affiliated with Browserstack in any way by the way.</p><h4><strong>Recommendation 3: </strong><a href="https://developer.mozilla.org/en-US/"><strong>MDN Web Docs</strong></a></h4><p>I absolutely love MDN. It’s essentially a list of all APIs available to you in JavaScript. Each comes with extremely comprehensive documentation. As a Vanilla JS developer, if you only allowed me access to a single site on the entire World Wide Web, that’s the one I would pick.</p><h4><strong>Recommendation 4: </strong><a href="https://progressier.com/"><strong>Progressier</strong></a></h4><p>I built it so I’m obviously biased but I can’t end the article without recommending Progressier. When building The Coronavirus App, it hit me that the entire block of functionality we call PWA (caching strategies, installability, push notifications) was unnecessarily annoying to implement. So I decided to build an abstraction for it — which you can add to your own app with a single line of code.</p><h3>That’s all folks!</h3><p>Have you built a PWA with Vanilla Javascript yet? How was your experience with it? What other tools would you recommend using?</p><p>If this article helped you in any way, please consider leaving a comment below 🙏</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c726c5b2f9e0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/create-a-pwa-from-scratch-with-vanilla-javascript-c726c5b2f9e0">Create a PWA from Scratch with Vanilla JS</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a PWA app manifest dynamically]]></title>
            <link>https://javascript.plainenglish.io/create-a-pwa-app-manifest-dynamically-3b3d45340b11?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b3d45340b11</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 06:51:07 GMT</pubDate>
            <atom:updated>2024-09-23T13:33:55.859Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create a PWA App Manifest Dynamically</h3><h4>Ever wondered how to create an app manifest with different icons on desktop and mobile?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*5kaCmmp24udg2OqgwvMWHw.png" /></figure><p>Every Progressive Web App has an <a href="https://developer.mozilla.org/en-US/docs/Web/Manifest">app manifest</a>, a simple JSON file that contains the basic information of your app, i.e. name, icon, description, etc.</p><p>If you just want to add PWA functionality to your existing web app, <a href="https://progressier.com/">Progressier</a> has everything you need (including dynamic app icons options). But if you want to create your own web app manifest dynamically, please read on.</p><h3>How it’s traditionally done</h3><p>When building your first PWA, the simplest way to proceed is adding a link to your app manifest directly in the &lt;head&gt; section of your HTML template.</p><p>Host manifest.json anywhere on your site. The resulting JSON file should look like this:</p><pre>{ <br>  &quot;short_name&quot;:&quot;Coronavirus&quot;, <br>  &quot;name&quot;:&quot;The Coronavirus App&quot;, <br>  &quot;background_color&quot;:&quot;#ffffff&quot;, <br>  &quot;theme_color&quot;:&quot;#ffffff&quot;, <br>  &quot;display&quot;:&quot;standalone&quot;, <br>  &quot;orientation&quot;:&quot;any&quot;, <br>  &quot;start_url&quot;:&quot;https://coronavirus.app&quot;,       <br>  &quot;scope&quot;:&quot;https://coronavirus.app&quot;, <br>  &quot;icons&quot;:[    <br>    {&quot;src&quot;:&quot;/icon512.png&quot;,&quot;sizes&quot;:&quot;512x512&quot;,&quot;type&quot;:&quot;image/png&quot;},<br>    {&quot;src&quot;:&quot;/icon192.png&quot;,&quot;sizes&quot;:&quot;192x192&quot;,&quot;type&quot;:&quot;image/png&quot;},      <br>    {src&quot;:&quot;/icon196.png&quot;,&quot;sizes&quot;:&quot;196x196&quot;,&quot;type&quot;:&quot;image/png&quot;} <br>  ] <br>}</pre><h3>Why you might want to do it differently</h3><p>While the method above is a perfectly valid way of dealing with web app manifests, there are legitimate cases when a static file won’t do and you’ll want to generate it dynamically instead:</p><ul><li>You need completely different icons on desktop and mobile</li><li>You want to host multiple distinct PWAs on the same domain</li><li>The PWA should look different for each logged-in user</li></ul><p>And there are probably many more valid examples. To generate your app manifest dynamically, you have two options: build it on your server when it’s requested by users. Or automatically generate it right in the browser (our preferred method).</p><blockquote><em>💡</em><strong> Learn more about whether Vue.js is a good choice for building PWAs:</strong></blockquote><p><a href="https://differ.blog/p/decoding-the-role-of-vue-js-in-progressive-web-app-pwa-development-c127df">Decoding the Role of Vue.js in Progressive Web App PWA Development</a></p><blockquote><em>👉</em> To read more such articles, <a href="https://differ.blog/"><strong>sign up for free on Differ</strong></a>.</blockquote><h3>Server-side dynamic app manifest generation</h3><p>Rather than hosting the file as a static file on your site, make the path to /manifest.json an API, which will allow you to generate the content of the JSON file programmatically based on whatever your needs are. Here is an example using Node.js/Express.js:</p><pre>app.get(&#39;/manifest.json&#39;, async function(req, res){ <br>  //for brevity, we&#39;re not including the isDesktop function here <br>  let iconUrl = isDesktop() ? &#39;/desktop.png&#39; : &#39;/mobile.png&#39;; <br>  let manifest = { <br>    name: &quot;App name&quot;, <br>    icons: [{ <br>     src: iconUrl, <br>     sizes:  &quot;512x512&quot;, <br>     type:&quot;image/png&quot; <br>    }] <br>  } <br>  res.header(&#39;content-type&#39;, &#39;application/json&#39;); <br>  return res.status(200).send(JSON.stringify(manifest)); <br>});</pre><h3>Client-side dynamic app manifest creation</h3><blockquote>JUNE 2022 UPDATE: Client-side dynamic app manifest generation is no longer a viable option. So don’t do the following. See comments for more.</blockquote><p>Most people don’t know that /manifest.json doesn&#39;t have to be an actual file. It works just fine with a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs">Data URL</a> (although there is a drawback — see comments).</p><p>No additional file to download from your server means faster load times and reduced server costs. And since the Data URL will be different every time you modify the content of your web app manifest, you don’t have to worry about the browser not updating its content accordingly.</p><p>In your client-side code, here is how you can create it:</p><pre>//for brevity, we&#39;re not including the isDesktop function here <br>let iconUrl = isDesktop() ? &#39;/desktop.png&#39; : &#39;/mobile.png&#39;; <br>let manifest = { <br>  name: &quot;App name&quot;, <br>  icons: [{ src: iconUrl, sizes: &quot;512x512&quot;, type:&quot;image/png&quot; }] <br>}; <br>let content = encodeURIComponent(JSON.stringify(manifest)); <br>let url = &quot;data:application/manifest+json,&quot;+content; <br>let element = document.createElement(&#39;link&#39;); <br>element.setAttribute(&#39;rel&#39;, &#39;manifest&#39;); <br>element.setAttribute(&#39;href&#39;, url); <br>document.querySelector(&#39;head&#39;).appendChild(element);</pre><p>At <a href="https://progressier.com/">Progressier</a>, we came across quite a few complex use cases of users needing completely different logos on their Android home screen, on their Android splash screen, on their iPhone splash screen, and on their Windows/Mac installed PWA, so we’ve designed our dashboard accordingly.</p><p>Behind the scenes, we use these user settings to generate their app manifest dynamically with the methods above.</p><p>Questions or feedback? Leave a comment below!</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b3d45340b11" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/create-a-pwa-app-manifest-dynamically-3b3d45340b11">Create a PWA app manifest dynamically</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling Opaque Responses in a Service Worker]]></title>
            <link>https://kevinbasset.medium.com/handling-opaque-responses-in-a-service-worker-cd072ea71ffd?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd072ea71ffd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 08:47:12 GMT</pubDate>
            <atom:updated>2021-12-27T08:50:23.883Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Learn more about opaque responses, why they’re a problem and how you should deal with them in your service worker.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Zzyp0AXWt4f7krqt.jpg" /></figure><p><a href="https://progressier.com/">Progressier</a> handles opaque responses automatically so that you don’t have worry about them. But if you’re interested in learning more about opaque responses, why they’re a problem and how you should deal with them in your service worker, please continue reading.</p><h3>What’s an opaque response?</h3><p>When a website requests an asset, e.g. a JPG image or a JavaScript file, it sends a request to a server. This server then responds with the requested image or JavaScript contents.</p><p>Problems start when the asset is hosted on a different domain than the requesting site. Browsers follow a mechanism called <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">Cross-Origin Resource Sharing</a> (or CORS). In a nutshell, it greatly limits what you can do with a resource located on a different domain.</p><p>One way to prevent issues is for the owner of the resource to add a access-control-allow-origin: * header to the response (also works with your specific domain instead of *). It essentially tells the browser <em>hey Chrome, just let anyone freely use that resource on their site</em>.</p><p>Here is where it gets interesting — even without this header, &lt;script&gt;, &lt;style&gt; or &lt;img&gt; tags will still be able to request and use these resources. But your Javascript code or service worker won&#39;t be allowed to read or otherwise modify them. Responses that the browser can use but that you as a developer cannot are called <em>opaque responses</em>.</p><h3>So… what’s the problem with opaque responses, exactly?</h3><p>When a server sends a response to a browser, it also sends a HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">response status code</a>, which tells the browser whether the request was successful or not.</p><p>Anything starting with 2xx usually means success. 5xx means there was an error with the server. And 4xx an error with the request.</p><p>For opaque responses, the response status code is always 0.</p><p>Your service worker has no way to know whether a request was successful or whether it resulted in an error. And because the request is made completely opaque, it does not contain any other clues that can tell you which way it went.</p><blockquote>Editor’s Note: I understand why opaque responses are necessary, but I honestly have no idea why ‘opaque’ also has to mean hiding the request status code. If anyone knows, I’m genuinely interested in learning more about the reasoning behind this choice.</blockquote><p>The problem is that most apps and websites do receive quite a few opaque responses. And if you choose not to cache them, these resources won’t be accessible offline at all when the network fails to send a successful response.</p><h3>Approach 1: The Last Resort Approach</h3><p>The approach we use at <a href="https://progressier.com/">Progressier</a> is to cache resources that have opaque responses but only serve them as a last resort — when there is no other response available in cache and the network couldn’t provide a response (because that server is down or the user is offline for example).</p><p>In that case, the choice is between showing an error (100% probability of error) versus showing an opaque response that may or not have been a successful response (unknown probability of error but by definition less than 100%).</p><h3>Approach 2: The No-Cache Approach</h3><p>The default behavior in <a href="https://developers.google.com/web/tools/workbox">Workbox</a> is to not cache opaque responses at all. This is another valid approach. It eliminates the uncertainty described above and it also ensures that the resource will NOT be available offline.</p><p>In cases where your front-end actually need to know what the error is (not just know that there is an error), this approach provides consistency and may be a better alternative.</p><h3>Recognizing and caching opaque responses</h3><p>An opaque response can be identified by the status code in the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response">Response</a> object. If it contains response.status === 0, then you&#39;re dealing with an opaque response.</p><p>Note that what you can do with opaque responses caching-wise is limited. You’ll necessarily have to call <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/clone">response.clone()</a> before putting it in cache. If you don’t, the body of the response will be consumed when you put in cache and it will fail when you also return it as a response to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent">fetch</a> event.</p><p>Response.clone() sometimes isn’t enough, i.e. if you need to alter the response before putting in cache. That’s why you can usually make a copy of the headers and body of the request, and recreate a response from scratch using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/Response">Response</a> constructor.</p><p>Well, with opaque responses… you can’t do that. The constructor simply doesn’t allow to create opaque responses.</p><h3>Conclusion</h3><p>When building <a href="https://progressier.com/">Progressier</a>’s caching strategy builder, I had quite a bit of fun figuring out the inner workings of service workers. And opaque responses were definitely one of the highlights! Their quirks can be hard to grasp at first, but once you understand how they behave, dealing with them becomes a lot easier.</p><p>If that article helped you understand anything about opaque responses, leave a comment. And if you have any questions, feel free to reach out to me 💪🎉😜</p><p><em>Originally published at </em><a href="https://dev.to/progressier/handling-opaque-responses-in-a-service-worker-fgd"><em>https://dev.to</em></a><em> on December 27, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd072ea71ffd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Force a PWA to Refresh its Content]]></title>
            <link>https://javascript.plainenglish.io/how-to-force-a-pwa-to-refresh-its-content-fef2c6ff3591?source=rss-39df85b82f79------2</link>
            <guid isPermaLink="false">https://medium.com/p/fef2c6ff3591</guid>
            <category><![CDATA[pwa-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[service-worker]]></category>
            <dc:creator><![CDATA[Kevin Basset]]></dc:creator>
            <pubDate>Fri, 17 Dec 2021 05:53:06 GMT</pubDate>
            <atom:updated>2021-12-17T12:18:10.520Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most common questions we get asked at <a href="https://progressier.com/?ref=medium20211217">Progressier</a> pertains to client-side caching. <em>How does one ensure a PWA always displays up-to-date data and assets while also making good use of caching?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NHoiAy4INEiwBRKl7FyoWg.png" /></figure><p>Although a PWA often looks and feels like a native app, from a technical perspective it really just works like any other website. When one opens a page, it loads assets (images, scripts, stylesheets…) and data (user data, product data…). These resources are fetched from the network and then used by the browser.</p><p>Enter the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching">HTTP cache</a> mechanism. In order to make loading websites faster, browsers cache these resources. On the initial load, an image will come from your server. On the following load, it may come from the cache instead. So if you update it in the meantime, the browser may display a stale version of that image. How can you prevent that?</p><h3>The Versioning Trick</h3><p>Versioning is probably the easiest way to force the browser to load a resource from your server. When you update a resource, add a parameter to the URL of the resource wherever your request in your code. For example, edit your client-side code to requestdomain.com/data.json?<strong>version=2</strong> instead of domain.com/data.json?<strong>version=1</strong>.</p><p>A browser will see these two URLs and consider them completely different assets. So it won&#39;t use a cached version of the former when the page explicitly requests the latter. A good practice is to append a version number (or any other query strings, really) to key resources in your build process, so you don’t have to do that manually every time you make a change.</p><h3>The Cache-Control Header</h3><p>When a server responds to a HTTP request successfully, it returns the asset itself (a JavaScript file, an image, a CSV file…) but it also sends headers — parameters that tell the browser what they are allowed or not allowed to do with the resource.</p><p>One of these headers is the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control">Cache-Control</a> header. It exists specifically so you can tell the browser how a particular resource should be cached (or not) and revalidated (or not).</p><p>If you control the server that responds to the request, you can set different Cache-Controlheaders and tell the browser how it should treat each particular resource. For instance, set the value of the Cache-Control header to no-cacheto forbid the browser to cache the resource at all.</p><p>Of course, this method only works with resources that you own — not third-party scripts, CSS libraries, Google fonts or images hosted somewhere else.</p><h3>The Network First Strategy</h3><p>Truth be told, the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching">HTTP Cache</a> mechanism is a bit antiquated. With it, all you can really tell the browser is whether or not a resource should be cached and until when.</p><p>There is another caching mechanism called the <a href="https://app.intercom.com/">Cache API</a>. And it’s available in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers">service workers</a>. <a href="https://progressier.com/">Progressier</a> uses that API for its caching strategy maker. You can define very specific rules for each type of resources without having to write a single line of code.</p><figure><img alt="Example a caching strategy that covers all resources" src="https://cdn-images-1.medium.com/max/1024/1*p6eDH-IcK8sBa2gFKJgseg.jpeg" /><figcaption>Use Network First and target all resources to prevent caching altogether</figcaption></figure><p>With the <em>Network First</em> strategy, resources will always be fetched from the network exclusively (so an error will be thrown if the network is somehow unavailable, e.g. if the user or the server go offline).</p><p>Of course, most of the time, you’ll want to be more specific and apply that strategy to resources that are mission critical and use more caching-friendly strategies for less essential resources (<a href="https://intercom.help/progressier/en/articles/5703064-what-s-a-caching-strategy">Stale-While-Revalidat</a>e for example).</p><h3>The Fake Reload Button</h3><p>With the first three methods, you’re essentially telling the browser whether a particular resource should be retrieved from the cache or the network when the page is loaded.</p><p>But once installed, opening a PWA may not always trigger a new page reload. You can launch a PWA from your home screen, do what you have to do with it, then launch another app, and go back to the PWA the next day.</p><p>If you haven’t closed the app or turned off your phone in the meantime, it will not reload the page — instead it will simply allow you to continue your session where you left off. If you, the app owner, updated resources in the meantime, then the user may still be using stale resources. How can you force the PWA to refresh its content then?</p><p>When we launched <a href="https://progressier.com/#story">The Coronavirus App</a> in January 2020, users were very demanding when it came to data freshness. We updated data every 15 minutes automatically, so it was absolutely critical to not let users see stale data (or we would receive tons of angry emails!).</p><p>But rather than wait for actual updates, we used a simple trick: when the user had spent more than half an hour on the page, we would present them with an option to reload the page (which they had no other choice but click) and fetch resources again. It looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*YJpD7UbqiFBPLcElpnWiyQ.jpeg" /></figure><p>Giving the illusion that something is happening is a powerful UX concept. In our case, the purpose was two-fold: make it look like the app was updated constantly (which it actually was — just not in a synchronized manner with that fake reload button) and avoid showing stale data.</p><h3>Conclusion</h3><p>So there you go. Three different caching methods to ensure your PWA stays updated and one little UX trick.</p><p>The versioning trick is probably the easiest way to go about this — and it works universally, whether you own the requested resources or not.</p><p>And if that’s not feasible easily in your build process, you can either use the Cache-Control header (for resources you own) or the Service Worker method to granularly define caching behaviors.</p><p>What do you think? Do you use other methods to keep your PWA updated?</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a><strong><em>.</em></strong><em> Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter here</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fef2c6ff3591" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-force-a-pwa-to-refresh-its-content-fef2c6ff3591">How to Force a PWA to Refresh its Content</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>