<?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 stefan judis on Medium]]></title>
        <description><![CDATA[Stories by stefan judis on Medium]]></description>
        <link>https://medium.com/@stefanjudis?source=rss-c3a0319fab53------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MOjts6TjboIU_MXV3CHn9g.jpeg</url>
            <title>Stories by stefan judis on Medium</title>
            <link>https://medium.com/@stefanjudis?source=rss-c3a0319fab53------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:14:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stefanjudis/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[Say goodbye to resource-caching across sites and domains]]></title>
            <link>https://medium.com/@stefanjudis/say-goodbye-to-resource-caching-across-sites-and-domains-b620cb00c92c?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/b620cb00c92c</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[safari]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Wed, 02 Dec 2020 10:03:05 GMT</pubDate>
            <atom:updated>2020-12-02T11:52:10.556Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.stefanjudis.com/notes/say-goodbye-to-resource-caching-across-sites-and-domains/"><strong><em>stefanjudis.com</em></strong></a><em> on October 18, 2020.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIdvFaffhXh4YHqJw0ibog.jpeg" /></figure><p>When I started doing web development, we all loaded jQuery from the official global jQuery CDN.</p><p>The idea was straightforward: if everybody loads the same jQuery script file (<em>cdn.jquery.com/jquery.latest.js</em> – or whatever URL it was back then), then the script file would be cached by the browsers, and other sites requesting the same script would benefit from the speedup of already cached resources. Users would have popular libraries like jQuery already sitting in their browser cache because earlier visited sites requested them.</p><p>This caching behaviour was possible because, at the time, the browser’s HTTP caches used the asset URL (<em>cdn.jquery.com/jquery.latest.js</em>) as a single cache key. Browsers use cache keys to figure out if and how to cache a resource. If these keys only consist of the resource URL, it allows the reuse of resources across sites and domains.</p><p>All this worked great, but as it is with many great inventions in web technology, <strong>cross-site resource caching enabled new ways to track users across different sites</strong>.</p><p>As an example, let’s assume Facebook loads a unique file in their logged-in area (<em>fb-logo-ajgdmaks839–as.svg</em> – I totally made that file path up); if I would know the file path to such a file, request it on <em>stefanjudis.com</em> and see a rapid response coming from the browser cache, I can almost be sure that the user has logged into Facebook lately.</p><h3>New HTTP cache keys in Google Chrome</h3><p><a href="https://bugs.webkit.org/show_bug.cgi?id=110269"><strong>Webkit (Safari) changed its caching strategy already in 2013</strong></a><strong> </strong>to prevent user tracking via the browser cache. Its cache keys are a combination of the requested resource URL and the top-level-domain requesting the resource.</p><p><em>☝️ Big thanks to</em><strong><em> </em></strong><a href="https://twitter.com/tomayac/status/1317861511784792067?s=20"><strong><em>Thomas Steiner who gave input on that matter</em></strong></a><em>.</em></p><p>On the bright side, this key structure prevents the mentioned tracking possibilities; unfortunately, it also leads to duplicated resources in the browser cache.</p><p>And… it hinders third-party resource sharing across the internet.</p><pre>Browsers duplicate resources with different keys:cdn.jquery.com/jquery.latest.js-amazon.co.uk<br>cdn.jquery.com/jquery.latest.js-www.stefanjudis.com</pre><p>Starting with v86, Chrome will be using combined cache keys, too. This change means that it’s time to say goodbye to third-party resource-sharing across the web. <a href="https://www.statista.com/statistics/544400/market-share-of-internet-browsers-desktop/"><strong>With Chrome’s market share of roughly 70%</strong></a>, most browsers hitting our sites will use partitioned browser caches from now on. Chrome went for combining the top-level site URL, the current frame site URL, and the resource URL. This approach is more granular than what Safari does, but the result is the same.</p><p>If your sites request the global jQuery, modules from <a href="https://unpkg.com/"><strong>unpkg.com</strong></a>, font files from <a href="https://fonts.google.com/"><strong>Google fonts</strong></a> or GA’s (Google Analytics) <em>analytics.js</em>, <strong>users will redownload the resources no matter if they downloaded and cached them for other sites already.</strong></p><p>What does this change mean for you? If your sites live on modern hosting that provides a CDN and supports HTTP/2, you can drop the third-parties and should ship all resources yourself. Relying on a third-party provides little value in 2020.</p><p>I have mixed feelings about these changes. It’s excellent that browsers consider privacy, but it looks like anything can be misused for tracking purposes these days. I wonder where we’re going with this… 😢</p><p>If you’re interested in learning more on this topic you can give <a href="https://shkspr.mobi/blog/2020/10/please-stop-using-cdns-for-external-javascript-libraries/"><strong>Terence Eden’s post “Please stop using CDNs for external Javascript libraries”</strong></a> or <a href="https://andydavies.me/blog/2018/09/06/safari-caching-and-3rd-party-resources/"><strong>Andy Davies’ post “Safari, Caching and Third-Party Resources”</strong></a> a read, too.</p><p>And hey, this post was trending on Hacker News. 🎉 If you’re interested,<strong> </strong><a href="https://news.ycombinator.com/item?id=24894135"><strong>here are the Hacker News comments</strong></a>.</p><p>Did you enjoy this article? <a href="https://twitter.com/stefanjudis"><strong>Stefan Judis</strong></a> will be speaking at the <a href="https://future.works/techconference/?utm_source=medium&amp;utm_medium=blog&amp;utm_term=102182&amp;utm_content=javascript-blogpost&amp;utm_campaign=fw-tech-conference"><strong>Future.Works Tech Conference</strong></a> on the 10<em>th of December</em>. You can learn more about him in his site <a href="https://www.stefanjudis.com/"><strong><em>stefanjudis.com</em></strong></a><em>.</em></p><p>You can catch <em>2 days </em>(Dec. 9th &amp; 10th) of coding and networking to learn <em>JavaScript</em> and <em>Java</em> with world-level tech speakers, live coding, workshops and career sessions.</p><p><em>Tickets are free </em>so get yours while they’re available.</p><p>You can learn more about the <a href="https://future.works/techconference/?utm_source=medium&amp;utm_medium=blog&amp;utm_term=102182&amp;utm_content=javascript-blogpost&amp;utm_campaign=fw-tech-conference"><strong><em>Future.Works Tech Conference</em></strong><em> </em><strong><em>here</em></strong></a> and <a href="https://landingjobs.typeform.com/to/B4KsKgRw"><strong><em>pre-register here</em></strong></a>.</p><p>We’re looking forward to seeing you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b620cb00c92c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to control and record voice calls with Node.js serverless functions]]></title>
            <link>https://itnext.io/how-to-control-and-record-voice-calls-with-node-js-serverless-functions-76b530f44d56?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/76b530f44d56</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[twilio]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Mon, 20 May 2019 17:29:16 GMT</pubDate>
            <atom:updated>2019-05-20T19:57:16.392Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many ways to communicate with your friends and family. You might use good old SMS, Whatsapp, emails and of course phone calls. Recently, I came across a surprising new way of communication. It all started with <a href="https://mobile.twitter.com/FischaelaMeer/status/1117718863095922689">my friend Michaela asking a question on Twitter.</a></p><blockquote><em>Would it be possible to generate an RSS feed out of Twilio voice calls?</em></blockquote><p>What she was looking for was a way to transform phone calls into an RSS feed referencing the recorded phone call. Why? Because she listens to many podcasts and sends very long voice messages to one of her friends via Whatsapp. As these messages usually don’t need a timely response, they both would prefer all the voice messages appear in their podcatchers rather than Whatsapp.</p><p>Let me introduce you to the idea of <a href="https://podbot.netlify.com/">“PodBot — the surprise podcast from your friends”</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*2U1Ne1VqUSGY8l8-.jpg" /></figure><p>The idea is a follows: All you have to do to publish a new podcast episode is to make a phone call. There is no need for a microphone setup, and you wouldn’t need to record, store or upload audio files to a podcast platform.</p><h3>Requirements for a voice call driven podcast site</h3><p>To create a phone call driven podcast site you need several things.</p><p>You need a phone number that you can control programmatically. Luckily, <a href="https://www.twilio.com/voice">Twilio Voice</a> provides this exact functionality.</p><p>Additionally, you need a way to store the information and transcriptions of the incoming phone calls. <a href="https://www.youtube.com/watch?v=UGN6EUi4Yio">Google sheets</a> or cloud databases can be used with Node.js and thus can provide a quick data store used in <a href="https://www.twilio.com/functions">Twilio Serverless Functions</a>.</p><p>Moreover, you need a site hoster that can serve your podcast site and feed.</p><p>Configuring programmable voice calls, downloading audio files and building a site with all the information is a lot of work. That’s why we split building <em>PodBot</em> and all its tasks into several tutorials.</p><p>In this first tutorial, we’ll use Twilio serverless functions to accept and manage phone calls, recordings, and voice transcriptions. In later tutorials, we’ll extend the functions to write to a data store, and we’ll use this data to build the podcast site using <a href="https://www.gatsbyjs.org/">Gatsby</a>, including the mandatory RSS podcast feed. Sound good? Let’s get started writing functions, then! 🎉</p><p>Here’s what you need today:</p><ul><li>A Twilio account to buy a phone number and accept calls</li><li>Node.js and npm installed</li></ul><h3>Function-driven voice calls to the rescue</h3><p>To define what happens when someone calls a Twilio phone number you have to provide some configuration in an XML-based format that is called <a href="https://www.twilio.com/docs/glossary/what-is-twilio-markup-language-twiml">TwiML</a>. The Twilio API requests this configuration right at the moment a call comes in. You can serve TwiML via <a href="https://www.twilio.com/blog/2017/11/twiml-bins-a-serverless-and-codeless-way-to-try-twilio.html">TwiML bins</a>, your custom-tailored application via webhooks, or serverless functions.</p><p>Before we implement this functionality, let’s recap and think about what we need to build. When someone calls <em>PodBot</em> we need to gather the following episode information:</p><ul><li>the title</li><li>the recording URL</li><li>the episode transcription</li></ul><p>Luckily, Twilio provides ways to retrieve all this call information. Below you see the TwiML configuration to ask for the episode title, record it and get a transcript of the recording.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Li07rxDtu_wKcmhe.jpg" /></figure><p>Let’s go into detail; when someone calls your Twilio number (step 1), Twilio asks your defined serverless functions for some TwiML configuration (step 2). The responded TwiML defines to ask for the title of the episode and to record the answer (step 3). Information about the complete recording should be sent to a /call-exit/ endpoint. The response of /call-exit/ will control what happens next by responding with more TwiML. The initial TwiML also specifies that the generated transcript should be sent to /transcribe-title/.</p><p>After Twilio receives this initial TwiML configuration, PodBot speaks to the caller saying “Tell me the title of your episode.” (step 4). Then it waits and records the answer until five seconds of silence has passed. Magic? Magic!</p><p>TwiML configurations like the one above can be chained together. This option makes it possible to ask for the episode title and record it followed by another action to end the phone call or to record more data like the episode itself.</p><p>Let’s set up the call handling in a new project. 🎉</p><p><strong>To keep this tutorial crisp and short we’ll only record and transcribe the episode title. You can find a solution at the end of the article that you can tweak to your needs and run locally quickly.</strong></p><h3>The creation of serverless functions</h3><p>Create a new directory for this project and also create three JavaScript files in the functions directory: call-enter.js, transcribe-title.js and call-exit.js.</p><pre>$ mkdir podbot-functions <br>$ cd podbot-functions <br>$ mkdir functions <br>$ touch functions/call-enter.js functions/transcribe-title.js functions/call-exit.js</pre><p>Each of these JavaScript files represents one HTTP endpoint. These endpoints have to respond with TwiML when the Twilio API asks for the configuration. To build a TwiML response you can use the <a href="https://www.npmjs.com/package/twilio-js">Twilio JS client</a> which is available globally in Twilio functions.</p><h3>The serverless entry point of your phone calls</h3><p>call-enter.js is the first endpoint Twilio requests when someone calls your number.</p><pre>// File: /functions/call-enter.js<br>&#39;use strict&#39;;<br><br>exports.handler = function(context, event, callback) {<br> let response = new Twilio.twiml.VoiceResponse();<br><br> // documentation for say<br> // -&gt; https://www.twilio.com/docs/voice/twiml/say<br> response.say(<br>   { voice: &#39;woman&#39;, language: &#39;en-US&#39; },<br>   &#39;Welcome to PodBot. Tell me the title of your episode.&#39;<br> );<br><br> // documentation for record<br> // -&gt; https://www.twilio.com/docs/voice/twiml/record<br> response.record({<br>   action: &#39;/call-exit&#39;,<br>   timeout: &#39;5&#39;,<br>   transcribe: &#39;true&#39;,<br>   transcribeCallback: &#39;/transcribe-title&#39;<br> });<br><br> callback(null, response);<br>};</pre><p>The above defined serverless function will be called <a href="https://www.twilio.com/docs/runtime/functions/invocation#handler-arguments">with </a><a href="https://www.twilio.com/docs/runtime/functions/invocation#handler-arguments">context, </a><a href="https://www.twilio.com/docs/runtime/functions/invocation#handler-arguments">event and a </a><a href="https://www.twilio.com/docs/runtime/functions/invocation#handler-arguments">callback</a>. The context object provides information about the current execution environment, event contains the request parameters passed into your function, and you can use the callback to respond to the request.</p><p>By calling the callback with null as the first argument, you signal that there were no errors. The second argument is a VoiceResponse which you can create by using the global Twilio object.</p><p>By defining the Record verb and its included action attribute, the second endpoint will be called after the caller is silent for five seconds.</p><p>Additionally, transcribeCallback defines the endpoint to retrieve the transcription when it&#39;s ready.</p><h3>Log the recording and say goodbye</h3><p>After the caller gives the name of the episode and remains silent for 5 seconds, the next endpoint (/call-exit/) is called to request additional configuration and continue the phone call.</p><pre>// File: /functions/call-exit.js<br>&#39;use strict&#39;;<br><br>exports.handler = function(context, event, callback) {<br> // do something with the data here<br> console.log(event.CallSid, event.RecordingUrl);<br> // CallSid: ‘CA3ac5f19...’<br> // RecordingUrl: ‘https://api.twilio.com/2010-04-01/Accounts/ACa3.../Recordings/RE92...’<br><br> const response = new Twilio.twiml.VoiceResponse();<br><br> // documentation for say<br> // -&gt; https://www.twilio.com/docs/voice/twiml/say<br> response.say({ voice: &#39;woman&#39;, language: &#39;en-US&#39; }, &#39;Thanks&#39;);<br><br> callback(null, response);<br>};</pre><p>Above you see the first important part of logging phone calls in serverless functions. Using the event object, you can access the data Twilio included in the request. The CallSid is a unique identifier for the phone call. This identifier stays the same for a phone call across the three functions.</p><p>The recording URL is also accessible. To request the recording in MP3 format, append .mp3 to the RecordingUrl property of the event object.</p><p>Right now this function only logs the information, but with CallSid and RecordingUrl available you can store this data in a database or other stores.</p><p>To finish the phone call, configure the VoiceResponse to say &quot;Thanks&quot;.</p><h3>The transcript logging</h3><p>The last function you need is transcribe-title.js. The /transcribe-title/ endpoint&#39;s only job is to log the transcript of the episode title. It doesn&#39;t have to provide any additional configuration. Call callback with null to signal that there were no errors and you&#39;re good to go.</p><pre>// File: /functions/transcribe-title.js<br>&#39;use strict&#39;;<br><br>exports.handler = function(context, event, callback) {<br> // do something with the data here<br> console.log(event.CallSid, event.TranscriptionText);<br> // CallSid: ‘CA3ac5f19...’<br> // RecordingUrl: “Hello everybody I hope...”<br><br> callback(null);<br>};</pre><p>At this point, you have three endpoints in place that can accept and control Twilio voice messages and log the recording URL and a transcript. With this setup, it’s time to test these with your first phone call.</p><h3>Run Twilio functions locally</h3><p>To run Twilio functions locally, you can use <a href="https://www.npmjs.com/package/twilio-run">twilio-run</a>. You can install the tool into your project but thanks to <a href="https://www.npmjs.com/package/npx">npx</a>, which comes with recent npm version, all you have to do is to run a single command in the root of your project directory.</p><p>This command downloads npm-run if it&#39;s not available in your environment and runs it. twilio-run looks for a functions directory which you have already prepared. The --live flag makes sure that the functions won&#39;t be cached when a local server is started. This flag allows you to write functions without the need for a command restart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*tlRwfMbbB9FX8O8n.jpg" /></figure><p>After running the command, the local server is started to debug and test your functions. Unfortunately, your localhost is not accessible on the internet. That’s the reason why twilio-run comes with another nifty configuration. If you run it with the --ngrok flag, it automatically spins up a publicly available URL which tunnels all requests to your local machine.</p><pre>$ npx twilio-run --live --ngrok</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*RmSK9OPwX3rRLbhR.jpg" /></figure><p>The provided URLs are what you need finally set up your call handling.</p><h3>Connect your Twilio number with serverless functions</h3><p><a href="https://support.twilio.com/hc/en-us/articles/223135247-How-to-Search-for-and-Buy-a-Twilio-Phone-Number-from-Console">After you buy a number</a>, you can set it up to use your local functions when a call comes in. On the configuration page for a particular number, you’ll find the setting for incoming calls. Select the webhook option for incoming calls and copy/paste the public URL for /call-enter/. Hit</p><p>“save” and call your number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*AC0kRaA90-pAqSzj.jpg" /></figure><p>When you call your number and tell PodBot the title of the podcast episode you should see the CallSid, RecordingUrl, and TranscriptionText logged to your terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*epUGSl2oWIGaGxG0.jpg" /></figure><p>Using twilio-run you can develop functions in your local environment right from the command line. If you&#39;re happy with the functionality of your local functions, you can then move them to <a href="https://www.twilio.com/console/runtime/functions/manage">the functions area in your Twilio console</a> and adjust your number to use your functions instead of webhooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sC81X_-kfh4-WjoL.jpg" /></figure><p>After you move the functions to Twilio and adjust the incoming call handling, you have a voice bot running in the cloud that is ready to log information for further usage. At that point, you’ll no longer require a local setup.</p><p>This tutorial was the first step of building PodBot. With these three functions, you’re able to manage and log phone calls using Twilio. If you want to play around with it, you can check out my <a href="https://github.com/stefanjudis/podbot-functions">podbot-functions</a> repo on GitHub or have a look at <a href="https://www.twilio.com/docs/runtime/functions">the function docs</a>.</p><p>If you want to start your own podcast business or just want to say “Hi” you can reach me under the following channels.</p><ul><li>Email: <a href="/service/mailto:sjudis@twilio.com">sjudis@twilio.com</a></li><li>Github: <a href="https://github.com/stefanjudis">stefanjudis</a></li><li>Twitter: <a href="https://twitter.com/stefanjudis">@stefanjudis</a></li></ul><p><em>Originally published at </em><a href="https://www.twilio.com/blog/control-and-record-voice-messages-with-node-js-serverless-functions"><em>https://www.twilio.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76b530f44d56" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-control-and-record-voice-calls-with-node-js-serverless-functions-76b530f44d56">How to control and record voice calls with Node.js serverless functions</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to send text messages from your static site using Netlify, Twilio and serverless functions]]></title>
            <link>https://itnext.io/how-to-send-text-messages-from-your-static-site-using-netlify-twilio-and-serverless-functions-efd6e383bd1a?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd6e383bd1a</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[twilio]]></category>
            <category><![CDATA[netlify]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Thu, 04 Apr 2019 11:55:06 GMT</pubDate>
            <atom:updated>2019-04-04T11:59:19.272Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s exciting times to be a Frontend developer. With the rise of modern technologies such as serverless functions, <a href="https://thepowerofserverless.info/">Frontend engineers can do things that usually only backend engineers could do</a>. This entails deploying scalable sites, <a href="https://sendgrid.com/">sending emails</a>, or creating HTTP endpoints. Due to the power of new service providers and countless APIs, building performant applications has become rather a game of connecting dots than building everything from the ground up.</p><p>In this article, I want to share how you can create and deploy a scalable static site on <a href="https://www.netlify.com/">Netlify</a> and how you can use serverless functions to send text messages using <a href="https://www.twilio.com/">Twilio</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1Hd1fDJCSYuZugHYV0QBA.jpeg" /><figcaption>Screenshot of 8-bit-revolution.netlify.com</figcaption></figure><p>You can see the final result on <a href="https://8-bit-revolution.netlify.com/">8-bit-revolution.netlify.com</a>. You can go there and tell me how much you love the good old 8-bit style via SMS. If you want to set-up a site similar to “8-bit revolution” you can have a look at the <a href="https://github.com/stefanjudis/8-bit-revolution">project’s readme</a>. It includes a one-click install button with which you can create an SMS sending website yourself. In the setup, you can configure the telephone numbers of the recipients and the text you want to send.</p><p>If you want to follow along instead and want to understand how it works, what you’ll need to get started are:</p><ul><li>A <a href="https://www.twilio.com/">Twilio</a> account</li><li>A <a href="https://www.netlify.com/">Netlify</a> account</li><li>A <a href="https://github.com/">GitHub</a> account</li><li><a href="https://nodejs.org/en/">Node.js</a> installed</li></ul><h3>Why static?</h3><p>HTML powers the web and serving HTML statically has a few advantages. Static sites are more secure because there is less computation involved. The HTML is pre-generated and files can be served 1:1 one from the server which reduces the number of attack vectors. Additionally, static sites are cheap. GitHub pages and other service providers mainly offer static site hosting for free. And lastly, static sites are scalable. Serving static files doesn’t need much computation power on the server-side and in case you need it, you can quickly put a CDN in front of your site to be ready to serve your millions of visitors.</p><p>Writing hundreds of plain HTML pages by hand can be cumbersome, though. This is why build tools and static site generators have become a common practice. These tools combine templates with Markdown files or API data to generate the static HTML.</p><p>This results in the need for a more complex setup. A server needs to generate the HTML and then upload the HTML to your static site host. This is where continuous integration systems (CI) like TravisCI come into play. These services allow you to rebuild your site when you push code updates or when the content was updated.</p><h3>Netlify is your CI, CDN and serverless platform</h3><p>Netlify is a fairly new service that solves this problem of increased complexity. You define a directory and a build script and they take care of the creation of your site and put it on a <a href="https://en.wikipedia.org/wiki/Content_delivery_network">global content delivery network</a> (CDN). You can use additional features like serverless functions or forms to enrich your static site with additional functionality — all included in one platform.</p><p>Sounds good? Let’s do it!</p><h3>Create your static website</h3><p>Create a new directory and include a dist subdirectory. dist will hold all the files that should be deployed by Netlify. You can place a barebones index.html file like the one below in there and you’re good to go.</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot;&gt;<br>  &lt;title&gt;8-bit revolution&lt;/title&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>  &lt;meta name=&quot;theme-color&quot; content=&quot;#fafafa&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;p&gt;8-bit rocks!&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Additionally, you have to define a command that should be run when you deploy the site. Initialize a new npm project in the project directory.</p><p>The --yes flag allows you to skip the questionnaire that usually comes with npm when you create a new project. The command creates a new package.json which is the configuration file for Node.js projects. Let’s add a dummy build command that only echoes a log message to the scripts property of the included JSON object.</p><p>Your package.json should look similar to the following:</p><pre>{<br>  &quot;name&quot;: &quot;8-bit-revolution-tut&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;echo \&quot;Building your new static site!\&quot;&quot;<br>  },<br>  &quot;repository&quot;: {<br>    &quot;type&quot;: &quot;git&quot;,<br>    &quot;url&quot;: &quot;git+https://github.com/stefanjudis/8-bit-revolution-tut.git&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;stefan judis &lt;sjudis@twilio.com&gt;&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;bugs&quot;: {<br>    &quot;url&quot;: &quot;https://github.com/stefanjudis/8-bit-revolution-tut/issues&quot;<br>  },<br>  &quot;homepage&quot;: &quot;https://github.com/stefanjudis/8-bit-revolution-tut#readme&quot;<br>}</pre><p><em>Note: the name, repository, author, bugs, and homepage properties will be different and tailored to your user and project.</em></p><p>You can run all defined script properties in your terminal using npm run followed by the property name. Executing npm run build will log “Building your new static site!” to the terminal. That’s not much yet and you will add more functionality to this script later in this tutorial.</p><p><a href="https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line">Initialize git in your project root and push it to a new GitHub repository.</a></p><p>After committing and pushing these two files to GitHub you’re ready to deploy the site. Head over to Netlify, login, and click “New site from Git” to connect your repository with Netlify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCQt9Zw8t3Vfz-XdFLOy7A.jpeg" /><figcaption>Site overview of Netlify admin area</figcaption></figure><p>After connecting with GitHub you’ll be able to choose your newly-created repository. Netlify will ask you about the branch and directory which should be deployed and, additionally, which script you want to execute during the deployment process. In this case, it will be master, dist and npm run build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZcBf1t9WGU5Xy4fm15roA.jpeg" /><figcaption>New site dialog to define build script and folder in Netlify admin area</figcaption></figure><p>Press “Deploy site” and see your static site making its way into the internet. The deploy will only take a couple of seconds and will be available at a random subdomain like frosty-mclean-c6c41c at Netlify. You can change this subdomain or connect <a href="https://www.netlify.com/docs/custom-domains/">your own domain</a> if you want to, too. 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6J8AlE2sBBcjtgl1XL2jw.jpeg" /><figcaption>First successful deploy</figcaption></figure><p>Congrats! With pressing “deploy site” you set up a new deployment pipeline.</p><p>The cool thing about the Netlify and GitHub connection is that whenever you push new code to GitHub, Netlify will get notified via <a href="https://en.wikipedia.org/wiki/Webhook">webhooks</a> and automatically deploy your site. It is also ready to accept requests from any system you use so that you can trigger rebuilds after different events such as updating content in a <a href="https://headlesscms.org/">remote content management system</a>.</p><h3>Add a form to allow user inputs</h3><p>For the case of sending messages, static HTML is not enough. You have to add a way to allow for user input like pressing a button or entering data. Luckily, Netlify provides <a href="https://www.netlify.com/docs/form-handling/">built-in form handling</a>. Replace the “8-bit rocks!” paragraph with the following form.</p><pre>&lt;form name=&quot;contact&quot; class=&quot;form&quot; method=&quot;POST&quot; data-netlify=&quot;true&quot;&gt;<br>    &lt;h1&gt;Wanna spread the word?&lt;/h1&gt;<br>    &lt;button class=&quot;btn&quot; type=&quot;submit&quot;&gt;Send messages!&lt;/button&gt;<br>&lt;/form&gt;</pre><p>The form has to include a data-netlify=”true” attribute. This tells Netlify that you want this form submission handled by their servers. Commit and push the code. Wait for the deploy to finish and voila – you can now handle form submissions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5yC2qR0Czxt58CzLNQrbA.jpeg" /><figcaption>First deploy including a form and a button</figcaption></figure><p>The data of all submitted forms will be available in the Netlify admin area under “Forms”. This makes it perfect for collecting data from contact forms and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmbdTE97JxrRBAnt-9M90Q.jpeg" /><figcaption>Netlify form submission success dialog</figcaption></figure><p>At this stage, when you submit the form, Netlify will show you a generic success message that tells you it received the form submission. You can change that by defining a page that should be redirected to with the action attribute on the form element.</p><p>I prefer to submit the form via JavaScript to avoid the redirect.</p><h3>Use Ajax to submit forms</h3><p>With the implementation of the globally-available <a href="https://developers.google.com/web/updates/2015/03/introduction-to-fetch">fetch</a> method, you can make requests directly from within the browser without needing to add any dependencies.</p><p>Before you start implementing the Ajax functionality, add two more HTML elements to the page. These elements will indicate success or error of the form submission request.</p><pre>&lt;p class=&quot;successMsg&quot; role=&quot;alert&quot; hidden&gt;Messages sent...&lt;/p&gt;<br>&lt;p class=&quot;errorMsg&quot; role=&quot;alert&quot; hidden&gt;Something went wrong...&lt;/p&gt;</pre><p>Add an inline script element to the bottom of the page. Using native DOM methods you can listen for the submit event of the form and apply custom functionalities like making an AJAX request.</p><pre>&lt;script&gt;<br>  const form = document.querySelector(&#39;form&#39;);<br>  form.addEventListener(&#39;submit&#39;, async event =&gt; {<br>    event.preventDefault();<br>    <br>    // disable button to prevent multiple submissions<br>    form.querySelector(&#39;button&#39;).disabled = true;<br><br>    // make the request to submit the form<br>    try {<br>      const response = await fetch(&#39;/&#39;, {<br>        method: &#39;post&#39;,<br>        headers: {<br>          &#39;Content-type&#39;: &#39;application/x-www-form-urlencoded; charset=UTF-8&#39;<br>        },<br>        // parse and submit all included form data<br>        body: new URLSearchParams(new FormData(form)).toString()<br>      });<br><br>      // if it was successful show success message<br>      if (response.status === 200) {<br>        document.querySelector(&#39;.successMsg&#39;).hidden = false;<br>      } else {<br>        document.querySelector(&#39;.errorMsg&#39;).hidden = false;<br>      }<br>    } catch (e) {<br>      console.error(e);<br>    }<br>  });<br>&lt;/script&gt;</pre><p>The fetch method returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">a promise</a>. If <a href="https://caniuse.com/#feat=async-functions">your browser support allows it</a> you can use an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">async function</a> as a submit handler to avoid callbacks and then-chains combined with await and a try/catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqaEkgERcRUwmHVzpaNfMA.jpeg" /><figcaption>Form submission with ajax enabled success message</figcaption></figure><p>Push the code and wait for the deploy. When you test the form submission you’ll see that the form submission works and that the site shows you a success message but it is not sending any messages yet.</p><p>Before you implement the SMS sending part let’s bring the 8-bit style back into the site. Copy <a href="https://github.com/stefanjudis/8-bit-revolution/blob/master/dist/styles.css">the styles from the example repository</a> and paste them into a new file styles.css in your dist directory. Additionally, add a link to a Google font which is referenced <a href="https://github.com/stefanjudis/8-bit-revolution/blob/master/dist/styles.css#L26">in the just-pasted styles</a> to the index.html.</p><pre>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot;&gt;<br>  &lt;title&gt;8-bit revolution&lt;/title&gt;<br>  &lt;!-- reference the new stylesheet --&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;/styles.css&quot; /&gt;<br>  &lt;!-- load Google Font to get get a nice 8-bit font --&gt;<br>  &lt;link<br>    href=&quot;https://fonts.googleapis.com/css?family=Maven+Pro|Yrsa|Press+Start+2P&quot;<br>    rel=&quot;stylesheet&quot;<br>  /&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>  &lt;meta name=&quot;theme-color&quot; content=&quot;#fafafa&quot;&gt;<br>&lt;/head&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5GIAUTvhGwyTlo5YwmAsWA.jpeg" /><figcaption>Deployed site with 8-bit style</figcaption></figure><p>Not too bad! Now that your site looks nice and “8-bit’y” let’s implement the SMS functionality.</p><h3>Reacting to submitted forms using serverless functions</h3><p>When a user submits the form nothing happens except Netlify stores the form data. To implement the SMS-sending functionality you can use <a href="https://www.twilio.com/docs/glossary/what-is-serverless-architecture">serverless functions</a> provided by Netlify. It’s recommended to use <a href="https://www.npmjs.com/package/netlify-lambda">the netlify-lambda npm package</a> to create these functions. Install the package via the command line.</p><pre>npm install --save netlify-lambda</pre><p><em>netlify-lambda</em> inlines all the dependencies included in your functions so that they become executable in the Netlify environment. Create a directory called functions and add a JavaScript file submission-created.js. <a href="https://www.netlify.com/docs/functions/#event-triggered-functions">Netlify follows naming conventions to run functions</a> after certain events. Additionally, you can give your function file a name that is not included in the list to spin up new HTTP endpoints, too.</p><pre>// submission-created.js<br>exports.handler = function(event, context, callback) {<br>  console.log(&#39;Submission created!&#39;)<br>};</pre><p>Before you can generate the function you have to define the directory in which it should be stored. Create a netlify.toml file inside of your project root. Define the [build] property and include the configuration that your generated ready-to-run functions will be stored in the .functions directory.</p><pre>[build]<br>  functions = &quot;.functions&quot;</pre><p>Adjust your package.json to build your serverless functions during deploys.</p><pre>{<br>  &quot;scripts&quot;: {<br>      &quot;build&quot;: &quot;netlify-lambda build functions&quot;<br>    } <br>}</pre><p>When you run npm run build locally it generates a new .functions directory including the functions that are ready to run on Netlify. The new .functions directory includes generated code and might not be worth checking into git and pushing to GitHub. Make sure to create a .gitignore file that includes the generated directory.</p><pre># .gitignore<br># generated functions<br>.functions</pre><p>With these adjustments, you can commit and push to GitHub. Netlify will automatically deploy the website including the function that runs when someone submits the form.</p><p>When you submit the form to tell the world about 8-bit and get to the function log in Netlify you will see the “Submission created!” message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghBAYILK9W6DX9hw-9n9Xw.jpeg" /><figcaption>Function log in Netlify admin area</figcaption></figure><h3>Sending SMS’s within a serverless function</h3><p>Your function is ready to react to form submission at this point and you can start sending text messages. To send messages with Twilio you have to define sensitive information like your account SID, your account token, and the phone numbers of the people you want to send messages to. Make sure these don’t make it into a public git repository.</p><p>Install the <a href="https://www.npmjs.com/package/dotenv">dotenv</a> package using npm install --save dotenv. It allows you to read configuration variables from a .env file in the root of the directory and makes them accessible in your serverless function via process.env. Create the .env file, include it in your .gitignore, and define the following values, replacing them with your own:</p><pre>TWILIO_ACCOUNT_SID = “YOUR-TWILIO-ACCOUNT-SID”<br>TWILIO_AUTH_TOKEN = “YOUR-TWILIO-AUTH-TOKEN”<br>BOT_NUMBER = “YOUR-BOUGHT-TWILIO-NUMBER”<br>BOT_MESSAGE = &quot;YOUR-MESSAGE&quot;<br>CONTACT_NUMBERS = &quot;NUMBERS-THAT-SHOULD-RECEIVE-A-MESSAGE&quot;</pre><p>To get all these values, <a href="https://www.twilio.com/console/">log into Twilio</a>. You can find your account SID and auth token in the dashboard. The auth token is very sensitive information because it can grant the same access as the current user has. I recommend to catch up on some <a href="https://www.twilio.com/blog/protect-phishing-auth-token-fraud">best practices to keep your auth token</a> secure before proceeding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HTAngjTD1SaYmbuJNyFuA.jpeg" /><figcaption>Twilio console including account sid and token</figcaption></figure><p>Next, you need to <a href="https://www.twilio.com/console/phone-numbers/search">buy a Twilio phone number</a>. Make sure you buy one with SMS capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SECK74aTKoBVS-X6aheNw.jpeg" /><figcaption>Twilio Console buy a number dialog</figcaption></figure><p>After you purchased a number you can define the message that will be sent and the numbers of your recipients in the configuration file yourself.</p><p>Your .env file should look like this then:</p><pre>TWILIO_ACCOUNT_SID = &quot;AC...&quot;<br>TWILIO_AUTH_TOKEN = &quot;a8...&quot;<br>BOT_NUMBER = &quot;+4915735982595&quot;<br>BOT_MESSAGE = &quot;8-bit rocks!&quot;<br>CONTACT_NUMBERS = &quot;+491761234567;+49170987654&quot;</pre><p>Adjust your function to access the above-defined values.</p><pre>// submission-created.js<br>// load the env file and make values accessible via process.env<br>require(&#39;dotenv&#39;).config();<br><br>const {<br>  TWILIO_ACCOUNT_SID,<br>  TWILIO_AUTH_TOKEN,<br>  CONTACT_NUMBERS,<br>  BOT_NUMBER,<br>  BOT_MESSAGE<br>} = process.env;<br><br>exports.handler = function(event, context, callback) {<br>  console.log(&#39;Submission created!&#39;)<br>  // the logic for sending the message will go here<br>};</pre><p>Install the Twilio helper library on the command line.</p><pre>npm install --save twilio</pre><p>With the Twilio helper library at hand, you can now send text messages. Replace the log message and add the following.</p><pre>// submission-created.js<br><br>// ...<br>// 👆 dotenv and process.env handling as above<br><br>// initialize the helper library client<br>const client = require(&#39;twilio&#39;)(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);<br><br>exports.handler = function(event, context, callback) {<br>  Promise.all(<br>    // split the string of several messages into single numbers<br>    // send message to each of them<br>    CONTACT_NUMBERS.split(&#39;;&#39;).map(num =&gt; {<br>      return client.messages.create({<br>        from: BOT_NUMBER,<br>        to: num,<br>        body: BOT_MESSAGE<br>      });<br>    })<br>  )<br>    .then(() =&gt; callback(null, { statusCode: 200, body: &#39;Created&#39; }))<br>    .catch(e =&gt; {<br>      console.log(e);<br>      callback(e);<br>    });<br>};</pre><p>To run your function locally add a serve command to the package.json to spin up a local development server.</p><pre>{<br>  &quot;scripts&quot;: {<br>      &quot;serve&quot;: &quot;netlify-lambda serve functions&quot;<br>    } <br>}</pre><p>The above netlify-lambda command will build and generate your function and open an HTTP endpoint. If you run npm run serve and then open <a href="http://localhost:9000/submission-created">http://localhost:9000/submission-created</a> it will run your function and send SMS messages. 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSJjxdM8YPD_kbPRoccw0A.jpeg" /><figcaption>“Created” response from Netlify function</figcaption></figure><p>Commit and push the new function and wait for the deploy. But wait… when you try to send an SMS by pressing the button on the deployed Netlify site you’ll discover that it doesn’t work yet. Remember that you put your .env file into .gitignore?</p><p>Working with .env files in combination with environment variables is a common practice to avoid leaking credentials. Using dotenv you can make sure your application works with both defined environment variables and .env configuration files. Locally dotenv reads the .env file and places values in process.env. In production – you have to define these environment variables in process.env yourself. This way you don’t have to place credentials in public places.</p><p>You can define environment variables in the Netlify admin area under “Build”, “Build settings” and “Build environment variables”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpQJAUAe8ig7NqJ_FO48sA.jpeg" /><figcaption>Environment variables defined in Netlify admin UI</figcaption></figure><p>Save the values and trigger a new build. Now hitting the button will show all your recipients that you love 8-bit. 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*-NZnkaFzlAokT5G7aDUy7A.png" /><figcaption>Received message in android sms dialog</figcaption></figure><p>You can find the final function implementation <a href="https://github.com/stefanjudis/8-bit-revolution/blob/master/functions/submission-created.js">on GitHub</a>.</p><h3>Conclusion</h3><p>In this tutorial, you learned how to deploy static sites with Netlify, enrich your sites using serverless functions, and send an SMS using Twilio.</p><p>Serverless functions are perfect connectors in the API-driven world we live in. They can connect services, accept webhooks, or even respond <a href="https://www.twilio.com/functions">to SMS messages</a>.</p><p>Let me know what messages you send. You can find <a href="https://github.com/stefanjudis/8-bit-revolution">the complete code on GitHub</a>. It includes <a href="https://github.com/stefanjudis/8-bit-revolution/blob/master/dist/index.html#L77-L91">a more sophisticated form submission flow</a> which you might want to check out.</p><p>If you have any questions please don’t hesitate to reach out on the following channels:</p><ul><li>Email: <a href="/service/mailto:sjudis@twilio.com">sjudis@twilio.com</a></li><li>Github: <a href="https://github.com/stefanjudis">stefanjudis</a></li><li>Twitter: <a href="https://twitter.com/stefanjudis">@stefanjudis</a></li></ul><p><em>Originally published at </em><a href="https://www.twilio.com/blog/a-how-to-send-text-messages-from-your-static-site-using-netlify-twilio-and-serverless-functions"><em>www.twilio.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd6e383bd1a" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-send-text-messages-from-your-static-site-using-netlify-twilio-and-serverless-functions-efd6e383bd1a">How to send text messages from your static site using Netlify, Twilio and serverless functions</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: background clip is configurable for every background gradient separately]]></title>
            <link>https://medium.com/@stefanjudis/til-background-clip-is-configurable-for-every-background-gradient-separately-fb956c147a77?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb956c147a77</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Fri, 18 Jan 2019 22:47:37 GMT</pubDate>
            <atom:updated>2019-01-18T22:47:37.429Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of my <a href="https://www.stefanjudis.com/today-i-learned/">Today I learned</a> series in which I share all my learnings regarding web development.</p><p>Today, I looked at <a href="https://codepen.io/thebabydino/pen/aQmRvq">a CodePen</a> created by <a href="https://twitter.com/anatudor">Ana Tudor</a>. <a href="https://twitter.com/chriscoyier">Chris Coyier</a> included this pen in an article about <a href="https://css-tricks.com/design-v17/">the new CSS-tricks redesign</a> to explain how they created a particular UI-element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZXp9oog5Ti0SxVp3.jpg" /></figure><p>What I thought was fascinating about the above element is that Ana used only a single HTML element to create it.</p><pre>&lt;!-- this is all the markup 😲 --&gt; <br>&lt;nav id=&quot;css&quot;&gt;&lt;/nav&gt;</pre><p>I created a new Pen and started rebuilding the same UI-element to understand how Ana had built it. The scss code to build this element is forty lines long, but most of the magic happens inside of the background property.</p><pre>#css { <br>  // ... <br>  background: <br>    linear-gradient(#333, #222) padding-box,<br>    linear-gradient(90deg, #db1d60, #ed4f32) <br>      0/ 50% no-repeat border-box,<br>    linear-gradient(-90deg, #eb7d01, #ed4f32 .5*65vw, rgba(#ed4f32, 0)) <br>      100% 101%/ 65% 75% no-repeat border-box;<br>}</pre><p>These lines are a lot to grasp, and it inevitably takes a moment (or a few more in my case) to understand what’s going on in there, but what surprised me immediately was the first gradient definition.</p><pre>linear-gradient(#333, #222) padding-box</pre><p>Wait a second? Can you define <a href="https://developer.mozilla.org/de/docs/Web/CSS/background-clip">background-clip</a> for every single gradient inside of the background property?</p><p><strong>It turns out you can!</strong></p><p><em>(… and I felt like I understood a tiny bit more how all these creative developers make impressive artwork with “just a few gradients”)</em></p><p>You can use the background property with different gradients and background-clips to create colorful borders. With a combination of border-box, padding-box, and content-box you can even style two different borders without any pseudo-elements. 🎉</p><pre>#css { <br>  /* padding defines the width of the red gradient background (2) */<br>  padding: .25em; </pre><pre>  /* border-width defines the width the blue gradient background (3) */<br>  border: .25em solid transparent; </pre><pre>  background: <br>    /* (1) most inner gradient */ <br>    linear-gradient(to bottom, #fff, #bbb) content-box, <br>    /* (2) red gradient */ <br>    linear-gradient(to right, #e94332, #a91302) padding-box, <br>    /* (3) blue gradient */ <br>   linear-gradient(to right, #0867a6, #4aa9e8) border-box;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/0*22OkETlaogjBEQaE.jpg" /></figure><p>If you want to know more about the background-clip property, content-box or padding-box – Ana Tudor wrote <a href="https://css-tricks.com/the-backgound-clip-property-and-use-cases/">a massive article on CSS-tricks</a> about precisely this topic.</p><p>Additionally, if you’re interested in how to create gradient borders, just recently there was <a href="https://css-tricks.com/gradient-borders-in-css/">an article published</a> (also on CSS-tricks) covering this topic.</p><p>Enjoy!</p><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/background-clip-is-configurable-for-every-background-gradient-separately/"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb956c147a77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: A preceding space prevents dangerous commands from going into history]]></title>
            <link>https://medium.com/@stefanjudis/til-a-preceding-space-prevents-dangerous-commands-from-going-into-history-952e80c2e666?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/952e80c2e666</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[bash]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Sun, 30 Dec 2018 10:41:17 GMT</pubDate>
            <atom:updated>2018-12-30T10:41:17.516Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://mobile.twitter.com/jawache/status/1078984435356315648">Assim Hussain shared on Twitter</a> that he executed a dangerous command by mistake. The command was still accessible in his shell history, and he pressed the UP arrow one time too much.</p><p>I have been in that situation, and you may have been, also. 🙈</p><p>I like about Twitter that sometimes people reply with useful tips to avoid future mistakes. So did <a href="https://mobile.twitter.com/feloy2/status/1078994363693363201">Philippe Martin</a>. He shared that <strong>commands executed with a preceding space will not go it into the session history.</strong> That sounds great!</p><pre># command goes into the history<br>$ delete everything</pre><pre># command does not go into the history <br>$  delete everything</pre><p>I tried it right away, but it didn’t work. I’m a <a href="http://www.zsh.org/">Zsh</a> user, and it turns out that you have to enable it via a config in your .zshrc.</p><pre>setopt histignorespace</pre><p>In bash, it should work right away (not tested).</p><p>There is one thing to mention though. After the execution of a command, every command will be accessible by pressing the UP arrow (this is a feature). Only when you execute another command preceding space command will be inaccessible.</p><p>This little trick prevents your future self from executing a dangerous command when pressing the UP arrow one time too much. 🎉</p><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/a-preceding-space-prevents-dangerous-commands-from-going-into-history/"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=952e80c2e666" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: Stylesheets do not only block rendering but also JavaScript execution]]></title>
            <link>https://medium.com/@stefanjudis/til-stylesheets-do-not-only-block-rendering-but-also-javascript-execution-cf7a8161e969?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7a8161e969</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 20:24:18 GMT</pubDate>
            <atom:updated>2018-11-18T20:24:18.053Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I learned that when you have the following snippet…</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;app.css&quot; /&gt;</pre><pre>&lt;script&gt;<br>  var script = document.createElement(&#39;script&#39;);<br>  script.src = &quot;analytics.js&quot;;<br>  document.getElementsByTagName(&#39;head&#39;)[0].appendChild(script);<br>&lt;/script&gt;</pre><p>… the inline JavaScript code snippet won’t be executed before the stylesheet is loaded. When you think about that, this makes a lot of sense because it may be that the JavaScript will access elements and any style-related values. I never thought about it, though.</p><p>All kudos to <a href="https://twitter.com/csswizardry">Harry Roberts</a> who described this behavior in <a href="https://csswizardry.com/2018/11/css-and-network-performance/#dont-place-link-relstylesheet--before-async-snippets">an excellent article</a>. Thanks Harry!</p><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/stylesheets-do-not-only-block-rendering-but-also-javascript-execution/"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7a8161e969" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: Property order is predictable in JavaScript objects since ES2015]]></title>
            <link>https://medium.com/@stefanjudis/til-property-order-is-predictable-in-javascript-objects-since-es2015-fbb0715785fa?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbb0715785fa</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Fri, 19 Oct 2018 10:43:11 GMT</pubDate>
            <atom:updated>2018-10-19T10:43:11.929Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of my <a href="https://www.stefanjudis.com/today-i-learned/">Today I learned</a> series in which I share all my learnings regarding web development.</p><p>Today’s learning surprised me!</p><p>I was reading Twitter and came across <a href="https://twitter.com/sebmck/status/1052268240028676096">a thread started by Sebastian McKenzie</a>. In this thread, he shared a React snippet that would rely on the order of specific properties in an object.</p><pre>styles({<br>  backgroundBlue: true,<br>  backgroundRed: true<br>});</pre><p>In the snippet above the background would be red as “it appears last”. If you do JavaScript for a while, you might immediately think — <strong>Wait, what</strong>!?!</p><p><em>In this post, I mainly share snippets and facts because I don’t want to repeat the content of resources listed at the end.</em></p><h3>The common misconception — “the order of JavaScript properties cannot be guaranteed”</h3><p>When you started writing JavaScript a few years ago, you might have heard the statement that the order of properties in JS objects is not predictable. I never came across an odd and unusual order of properties, but I always followed the rule “never rely on property order”.</p><h3>The internal ownPropertyKeys method</h3><p>It turns out — since ES2015 there are methods that are based on specific rules defining the order of properties, and apart from one particular case the order is chronological. The order of properties in an object depends on the type of the included properties and their values.</p><p>Looking at the spec the rules are defined in <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys">the internal “ownPropertyKeys” method</a>. Which is used for example by fairly new methods Object.getOwnPropertyNames and Reflect.ownKeys.</p><p>What is interesting is that there was a spec change of e.g. Object.keys from <a href="https://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.14">ES5</a> to <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-object.keys">ES6</a>. The ES6 spec defines that Object.keys also relies on ownPropertyKeys which makes it predictable in today&#39;s browsers, too.</p><p>This also means that you have to be careful with this method, though, and shouldn’t rely on a predictable order using Object.keys because the results <a href="https://www.reddit.com/r/javascript/comments/9ozyn3/property_order_is_predictable_in_javascript/e7yhm3g/">may vary depending on the browser implementation</a>.</p><p>But enough of the theory: let’s have a look at the defined property order for methods implementing ownPropertyKeys.</p><h4>1. Integer Indices</h4><p>All properties that are integer indices appear first in the overall object property order and are sorted numerically.</p><pre>const objWithIndices = { <br>  23: 23,<br>  &#39;1&#39;: 1,<br>  1000: 1000<br>}; </pre><pre>console.log(Reflect.ownKeys(objWithIndices));<br>// [1, 23, 1000]<br>// ☝️ following numeric order</pre><h4>2. Strings (that are no integers)</h4><p>Properties that do not count to integer indices and are not of type Symbol come next and follow chronological order.</p><pre>const objWithStrings = {<br>  &#39;bar&#39;: &#39;bar&#39;,<br>  &#39;01&#39;: &#39;01&#39;<br>};</pre><pre>objWithStrings.last = &#39;last&#39;;<br>objWithStrings[&#39;veryLast&#39;] = &#39;veryLast&#39;; console.log(Reflect.ownKeys(objWithStrings));<br>// [&#39;bar&#39;, &#39;01&#39;, &#39;last&#39;, &#39;veryLast&#39;]<br>// ☝️ following chronological order</pre><h4>3. Symbols</h4><p>At last, Symbols follow a chronological order, too.</p><pre>const objWithSymbols = {<br>  [Symbol(&#39;first&#39;)]: &#39;first&#39;,<br>  [Symbol(&#39;second&#39;)]: &#39;second&#39;<br>}; </pre><pre>objWithSymbols[Symbol(&#39;last&#39;)] = &#39;last&#39;; console.log(Reflect.ownKeys(objWithSymbols));<br>// [Symbol(first), Symbol(second), Symbol(last)]<br>// ☝️ following chronological order</pre><h3>All together</h3><p>When you combine these rules, you’ll see that integers are always in the “front row” of object properties followed by strings and Symbols. <strong>Moreover, we can control the order of the string and Symbol properties because they’re chronological!</strong></p><pre>const obj = <br>  &#39;2&#39;: &#39;integer: 2&#39;,<br>  &#39;foo&#39;: &#39;string: foo&#39;,<br>  &#39;01&#39;: &#39;string: 01&#39;,<br>  1: &#39;integer: 1&#39;,<br>  [Symbol(&#39;first&#39;)]: &#39;symbol: first&#39;<br>};</pre><pre>obj[&#39;0&#39;] = &#39;0&#39;;<br>obj[Symbol(&#39;last&#39;)] = &#39;symbol: last&#39;;<br>obj[&#39;veryLast&#39;] = &#39;string: very last&#39;; </pre><pre>console.log(Reflect.ownKeys(obj));<br>// [ &quot;0&quot;, &quot;1&quot;, &quot;2&quot;, &quot;foo&quot;, &quot;01&quot;, &quot;veryLast&quot;, Symbol(first), Symbol(last) ]<br>// -&gt; 1. integers in numeric order<br>// -&gt; 2. strings in chronological order<br>// -&gt; 3. Symbols in chronological order</pre><p><em>Edited: As Malgosia Stepniak pointed out “own property order” is </em><a href="https://twitter.com/malgosiastp/status/1052539495453773824"><em>only fully supported in modern browsers and not in e.g. IE</em></a><em>.</em></p><h3>Additional resources</h3><p>Thanks to Axel who wrote about this three years ago already. :)</p><ul><li><a href="http://2ality.com/2015/10/property-traversal-order-es6.html#traversing-the-own-keys-of-an-object">The traversal order of object properties in ES6</a> by <a href="https://twitter.com/rauschma">Axel Rauschmayer</a></li><li><a href="https://tc39.github.io/ecma262/#sec-ordinaryownpropertykeys">ECMAScript® 2019 Language Specification — OrdinaryOwnPropertyKeys</a></li><li><a href="https://stackoverflow.com/questions/30076219/does-es6-introduce-a-well-defined-order-of-enumeration-for-object-properties">“Does ES6 introduce a well-defined order of enumeration for object properties?”</a> on Stack Overflow</li></ul><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbb0715785fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three input element properties that I discovered while reading MDN]]></title>
            <link>https://medium.com/hackernoon/three-input-element-properties-that-i-discovered-while-reading-mdn-662ee0b4f17c?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/662ee0b4f17c</guid>
            <category><![CDATA[reading-mdn]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[input-element-properties]]></category>
            <category><![CDATA[input-element]]></category>
            <category><![CDATA[mdn]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Sun, 02 Sep 2018 13:44:52 GMT</pubDate>
            <atom:updated>2019-05-18T04:27:49.029Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was reading <a href="https://hackernoon.com/tagged/twitter">Twitter</a> and stumbled across <a href="https://twitter.com/dan_abramov/status/1035190868876177409">a tweet by Dan Abramov</a>. He shared a short code snippet that caught my eye. It included some JavaScript which accessed an input element from the DOM (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">Document Object Model</a>) and read or changed some of its properties. What was exciting and surprising to me was the property defaultValue.</p><p>I immediately opened <a href="https://hackernoon.com/tagged/mdn">MDN</a> to read more about this property of HTTMLInputElements and stumbled upon a few more properties that I wasn&#39;t aware of, which lead me to write this quick article.</p><p>So here we go!</p><h3>defaultValue</h3><p>This is Dan’s Tweet example — let’s have a quick look and assume you have some HTML and query an input element which has a value attribute (attributes are defined in the HTML whereas properties belong to JavaScript objects) defined.</p><pre>&lt;input type=&quot;text&quot; value=&quot;Hello world&quot;&gt;</pre><p>You can now grab this element and start tinkering around with it.</p><pre>const input = document.querySelector(&#39;input&#39;); console.log(input.value);        // &#39;Hello world&#39;<br>input.value = &#39;New value&#39;;<br>console.log(input.value);        // &#39;New value&#39; console.log(input.defaultValue); // &#39;Hello world&#39;</pre><p>As you see that the value defined in the attribute value is initially reflected in the element property value. That makes total sense to me. When you now change value, you can still access the &quot;initial value&quot; using defaultValue (for checkboxes defaultChecked is also available). Pretty cool!</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#Properties">The MDN definition</a> for defaultValue is a follows:</p><blockquote><em>[It] returns / sets the default value as initially specified in the HTML that created this object.</em></blockquote><p>If you like you can play around with the code in <a href="https://codepen.io/stefanjudis/pen/eLvMMx">a CodePen</a>.</p><h3>indeterminate</h3><p>The indeterminate property is a fascinating one. Did you know that checkboxes can have an additional visual state other than checked and not checked? indeterminate is a property (there is no attribute for it) that you can use to put this little dash into a checkbox that you may have seen every now and then.</p><pre>const input = document.querySelector(&#39;input&#39;);<br>input.indeterminate = true;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*5zkdntdihVRenby_.png" /></figure><p>Setting indeterminate to true doesn&#39;t have any effect on the value of the checkbox, and the only reasonable use case I can think of are nested checkbox like <a href="https://css-tricks.com/indeterminate-checkboxes/">Chris Coyier describes on CSSTricks</a>.</p><p>indeterminate doesn&#39;t work only for checkboxes though. It also can be used for radio buttons and progress elements. Let&#39;s take a group of radio buttons in which no radio button is selected. When you&#39;re not preselecting one element in a group of radio buttons none of them is selected and also none of them is not selected – thus all of them are in indeterminate state.</p><p>What’s cool is, that you can also use the CSS pseudo class :indeterminate pseudo-class to selected elements which could come in handy to show particular UI components when no radio button in a group is selected yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*AB1CtGbN8QoyHzK_.png" /></figure><pre>.msg {<br>  display: none;<br>}</pre><pre>input:indeterminate ~ .msg {<br>  display: block;<br>}</pre><p>What is interesting about the property indeterminate is that you can set it to true or false and this will affect the pseudo-class for checkboxes but not for radios. <strong>Dealing with radio buttons the actual selection state of a group is always right</strong>.</p><p>And only to mention it for the sake of completion <a href="https://developer.mozilla.org/de/docs/Web/HTML/Element/progress">progress elements</a> will also match a selector including :indeterminate when they don&#39;t have a value attribute defined.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#Properties">The MDN definition</a> for indeterminate is a follows:</p><blockquote><em>[It] indicates that a checkbox or radio buttons have no value and are in indeterminate state. Checkboxes change the appearance to resemble a third state. Does not affect the value of the checked attribute, and clicking the checkbox will set the value to false.</em></blockquote><p>If you like you can play around with the code in <a href="https://codepen.io/stefanjudis/pen/WgpzYy">a CodePen</a>.</p><h3>selectionStart, selectionEnd and selectionDirection</h3><p>These three properties can be used to figure out what a user selected and they are very straightforward to use. If the user selects text in an input field, you can use these to evaluate what was selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*m49GKXpAW548Su2U.png" /></figure><pre>const input = document.querySelector(&#39;input&#39;);</pre><pre>setInterval( _ =&gt; {<br>  console.log(<br>    input.selectionStart,<br>    input.selectionEnd,<br>    input.selectionDirection;<br>  ); // e.g. 2, 5, &quot;forward&quot;<br>}, 1000);</pre><p>What I did to test this is that I defined an interval which logs the selection values every second. selectionStart and selectionEnd return numbers describing the position of my selection but selectionDirection surprisingly returns none when you select things with your mouse or trackpad but forward or backward when you select text using SHIFT and the arrow or control keys.</p><p>If you like you can play around with the code in <a href="https://codepen.io/stefanjudis/pen/yxMjWe">a CodePen</a>.</p><p>And that’s it. :)</p><h3>Quick (and short) conclusion</h3><p>MDN is a fantastical resource. Even after using input elements for eight years now there are always new things to discover, and this is what I love about web development. Personally, I try to read random MDN articles regularly (I have a daily Slack-bot that reminds me to open <a href="http://bit.ly/randommdn">bit.ly/randommdn</a>) because there are always things to discover and I can only highly recommend it!</p><p>Thanks for reading! ❤️</p><p><em>Originally published at </em><a href="https://www.stefanjudis.com/blog/three-input-element-properties-that-i-discovered-while-reading-mdn/"><em>www.stefanjudis.com</em></a><em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=662ee0b4f17c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/three-input-element-properties-that-i-discovered-while-reading-mdn-662ee0b4f17c">Three input element properties that I discovered while reading MDN</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: SVGs have additional pointer-events properties]]></title>
            <link>https://medium.com/@stefanjudis/til-svgs-have-additional-pointer-events-properties-2652ef38ed87?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/2652ef38ed87</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[svg]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 11:16:39 GMT</pubDate>
            <atom:updated>2018-08-02T11:16:39.193Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I came across <a href="https://codepen.io/MartijnCuppens/pen/MBjqbM?editors=1100">this example</a> about certain things you can do with pointer-events in CSS.</p><pre>.foo {<br>  pointer-events: visiblePainted;<br>}</pre><p>visiblePainted is something I haven&#39;t seen before and it turns out that SVGs several other values for the pointer-events property:</p><ul><li>visiblePainted</li><li>visibleFill</li><li>visibleStroke</li><li>visible</li><li>painted</li><li>fill</li><li>stroke</li><li>all</li></ul><p>You can control very granular how elements in an SVG should behave and it’s not bound to the typical “web development boxes”. If you want to read more <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events">MDN</a> has you covered. :)</p><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/svgs-have-additional-pointer-events-properties"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2652ef38ed87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: Element.prototype.matches can be used to check if an element includes a certain class]]></title>
            <link>https://medium.com/@stefanjudis/til-element-prototype-matches-can-be-used-to-check-if-an-element-includes-a-certain-class-109ab2406cd3?source=rss-c3a0319fab53------2</link>
            <guid isPermaLink="false">https://medium.com/p/109ab2406cd3</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[stefan judis]]></dc:creator>
            <pubDate>Mon, 16 Jul 2018 07:11:39 GMT</pubDate>
            <atom:updated>2018-07-16T07:13:13.568Z</atom:updated>
            <content:encoded><![CDATA[<p>To figure out if an element contains a particular class is a quite common operation when building interfaces. Today I came across an article by <a href="https://twitter.com/D__Gilbertson">David Gilbterson</a> which describes <a href="https://hackernoon.com/15-html-element-methods-youve-potentially-never-heard-of-fc6863e41b2a">“15 HTML element methods you’ve potentially never heard of”</a> and it introduced me to Element.prototype.matches. This element method can be used to check if an element includes a certain class and is way shorter than element.classList.contains. 🎉</p><pre>const elem = querySelector(&#39;.foo&#39;);</pre><pre>elem.classList.contains(&#39;bar&#39;); // true<br>elem.matches(&#39;.bar&#39;);           // true</pre><p><em>Originally published at </em><a href="https://www.stefanjudis.com/today-i-learned/element-prototype-matches-can-be-used-to-check-if-an-element-includes-a"><em>www.stefanjudis.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=109ab2406cd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>