<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: chen4119</title>
    <description>The latest articles on DEV Community by chen4119 (@chen4119).</description>
    <link>https://dev.to/chen4119</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F718517%2Fc0c7aa23-71c3-46f4-8c5a-134eaae7ba17.png</url>
      <title>DEV Community: chen4119</title>
      <link>https://dev.to/chen4119</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chen4119"/>
    <language>en</language>
    <item>
      <title>Netlify vs Cloudflare pages vs AWS Amplify</title>
      <dc:creator>chen4119</dc:creator>
      <pubDate>Tue, 16 Nov 2021 16:28:00 +0000</pubDate>
      <link>https://dev.to/chen4119/netlify-vs-cloudflare-pages-vs-aws-amplify-1n5k</link>
      <guid>https://dev.to/chen4119/netlify-vs-cloudflare-pages-vs-aws-amplify-1n5k</guid>
      <description>&lt;p&gt;I've been using &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; for a few years now to host my static website and really love how easy it was to get going.  Before Netlify, I hosted my static site on AWS S3 and that experience was painful.  You need to configure S3 for public and CORS access, add cloudfront, then set up a custom domain.  It's a lot of work just to deploy a static website so I'm very happy when I found Netlify.  I know &lt;a href="https://pages.cloudflare.com/"&gt;Cloudflare pages&lt;/a&gt; and &lt;a href="https://aws.amazon.com/amplify/"&gt;AWS Amplify&lt;/a&gt; also provide an easy way to host static websites and I finally had the chance to try them out.  Here are some thoughts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ease of use
&lt;/h2&gt;

&lt;p&gt;Both Netlify and Cloudflare made it really easy to get started and deploy a static website directly from your Github repo.  I'll say overall Netlify has a better user experience compare to Cloudflare because it's site is more intuitive and visually appealing whereas Cloudflare pages feel more barebone.  One major downside for Cloudflare is that there is no federated login.  You need to use an email and password to create a Cloudflare account whereas for Netlify, you can just use your Github credential.  In this day and age where we all have hundreds of online accounts, I'll prefer not to have another password for Cloudflare.&lt;/p&gt;

&lt;p&gt;AWS Amplify also kept it really easy to deploy a static website but it's hard to say AWS Amplify is just as easy as Netlify and Cloudflare pages simply because AWS Amplify is a small feature within the AWS beast.  For those who are already familiar with AWS, Amplify will feel pretty simple but new users will be overwhelmed by so much options.  In terms of user experience, it definitely still lags Netlify and Cloudflare.  Instead of filling out a simple form, Amplify makes you edit the config blob below.  Not a big deal but it definitely feel more like a roadblock than a welcome sign.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1w-7BiYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qe5f78xx9bayfxy2zzi7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1w-7BiYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qe5f78xx9bayfxy2zzi7.png" alt="AWS Amplify console screenshot" width="880" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom domain
&lt;/h2&gt;

&lt;p&gt;Both Netlify and AWS Amplify allow you to easily set up custom domains with free ssl certificate.  It works with any third party DNS provider, you just need to set up an ALIAS record for it to work.&lt;/p&gt;

&lt;p&gt;Cloudflare pages on the other hand will force you to use their DNS service in order to set up custom domain.  It won't work with third party DNS providers.  This might be a deal breaker for some people but at least Clouflare offers a free plan for their DNS service and it's really fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build time
&lt;/h2&gt;

&lt;p&gt;I generated my website with &lt;a href="https://sambal.dev"&gt;Sambal&lt;/a&gt; static site generator.  Below is a timing of how fast each platform took from the moment I commit to github to a deployed website.  AWS Amplify was the fastest while Cloudflare took the longest.  For some reason Cloudflare took close to 2 minutes just to initialize the build environment.  By that time, AWS Amplify had already deployed my website.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Build time&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AWS Amplify&lt;/td&gt;
&lt;td&gt;1m 58s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Netlify&lt;/td&gt;
&lt;td&gt;2m 33s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare pages&lt;/td&gt;
&lt;td&gt;2m 53s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  TTFB test
&lt;/h2&gt;

&lt;p&gt;To test how my static website perform across all regions around the world, I deployed the same website to all 3 platforms then use &lt;a href="https://speedvitals.com/ttfb-test"&gt;SpeedVitals TTFB test&lt;/a&gt; to test the time to first byte across 25 different locations without using custom domain.  I hit each platform with their native URL.  Here is the average latency for the 3 platforms across different regions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Americas&lt;/th&gt;
&lt;th&gt;Europe&lt;/th&gt;
&lt;th&gt;Asia&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare pages&lt;/td&gt;
&lt;td&gt;146ms&lt;/td&gt;
&lt;td&gt;107ms&lt;/td&gt;
&lt;td&gt;148ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS Amplify&lt;/td&gt;
&lt;td&gt;142ms&lt;/td&gt;
&lt;td&gt;155ms&lt;/td&gt;
&lt;td&gt;294ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Netlify&lt;/td&gt;
&lt;td&gt;186ms&lt;/td&gt;
&lt;td&gt;67ms&lt;/td&gt;
&lt;td&gt;271ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Overall Cloudflare seem to have consistently good latency across different regions.  I ran the test multiple times for each platform.  The first test is always the worst because the CDN hasn't cached anything yet.  Subsequent tests always show better latency.  The average latencies reported above are measured after 3 - 4 tries to get a more accurate picture.  I noticed with Cloudflare, it took just 2 tries to get consistently good results and it felt like once your page is cached, the traffic is always fast.  AWS Amplify is somewhere in the middle, while Netlify results can vary quite a lot on different tries.  Sometimes it's fast and sometimes it felt like there's a cache miss somewhere so it went back to your origin server.&lt;/p&gt;

&lt;p&gt;To get a better picture, let's also look at the worst latency measured for the 3 platforms across different regions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Americas&lt;/th&gt;
&lt;th&gt;Europe&lt;/th&gt;
&lt;th&gt;Asia&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare pages&lt;/td&gt;
&lt;td&gt;232ms&lt;/td&gt;
&lt;td&gt;181ms&lt;/td&gt;
&lt;td&gt;363ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS Amplify&lt;/td&gt;
&lt;td&gt;187ms&lt;/td&gt;
&lt;td&gt;184ms&lt;/td&gt;
&lt;td&gt;407ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Netlify&lt;/td&gt;
&lt;td&gt;744ms&lt;/td&gt;
&lt;td&gt;140ms&lt;/td&gt;
&lt;td&gt;1100ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;From this table, it's more obvious that Netlify latency can be pretty bad at some locations although it seems to be consistently great in Europe.  Every platform has the worst latency in Asia.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Netlify is a great platform for users who don't want to deal too much with technical stuff.  They just want to get their static website up and running.  It's easy to use and it offers pretty much anything you'll need to run a professional website.  Serverless backend, A/B testing, user authentication, forms, etc.  All these features with minimal coding.&lt;/p&gt;

&lt;p&gt;Cloudflare is a great platform for developers who don't mind jumping through a few hoops to get the best performance.  Cloudflare DNS is one of the best DNS provider available and Cloudflare pages has consistently low latency across the globe.  The UX feels barebone and site navigation can be confusing but for the speed you get, I'm sure you can suck it up.&lt;/p&gt;

&lt;p&gt;AWS Amplify is a great choice for existing AWS users or people who don't mind getting their hands dirty with AWS.  It has a fast build time and good latency across the globe.  It integrates with every other AWS offering so you don't have to worry about the limits of the platform as you might with Netlify or Cloudflare.  It has a steeper learning curve but the end result of being familiar with AWS is worth it.&lt;/p&gt;

</description>
      <category>netlify</category>
      <category>cloudflare</category>
      <category>webdev</category>
      <category>aws</category>
    </item>
    <item>
      <title>Json-ld spices up the staticness of static site generator</title>
      <dc:creator>chen4119</dc:creator>
      <pubDate>Wed, 27 Oct 2021 14:52:43 +0000</pubDate>
      <link>https://dev.to/chen4119/json-ld-spices-up-the-staticness-of-static-site-generator-3i72</link>
      <guid>https://dev.to/chen4119/json-ld-spices-up-the-staticness-of-static-site-generator-3i72</guid>
      <description>&lt;p&gt;The best thing about static site generator is the simplicity.  All you need is a couple of markdown files, html templates, and the generator can spit out a speedy website with good old static HTML and CSS.  For a lot of websites, this is all you need and that's why static site generators are so popular.&lt;/p&gt;

&lt;p&gt;As your website start getting bigger though, the limits of static site generator becomes more apparent.  The most glaring limitation is that there is just no easy way to relationalize or join data like you can easily do in a database.  To illustrate my point, consider a blogpost markdown&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;blogpost"&lt;/span&gt;
&lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2021-10-17&lt;/span&gt;
&lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;John Smith&lt;/span&gt;
  &lt;span class="na"&gt;twitter&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="s"&gt;john&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;

Content of the blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The relationship between the author to blogpost is one to many.  John can write many blogposts but there is no easy way to normalize the one to many relationship in a static markdown file.  You can only duplicate john's info in every blogpost which is not ideal.  You might have noticed that the solution many blog themes took is to simply keep the author's info in the global config file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/yinkakun/gatsby-starter-glass/blob/master/gatsby-config.js"&gt;Here&lt;/a&gt; is an example for Gatsby, &lt;a href="https://github.com/dirkfabisch/mediator/blob/master/_config.yml"&gt;here&lt;/a&gt; is an example for Jekyll, and &lt;a href="https://github.com/gethugothemes/liva-hugo/blob/master/exampleSite/config.toml"&gt;here&lt;/a&gt; for Hugo.  Again, not ideal, but it'll work for a personal blog.  Once you have more than one author, the UI theme will need a major refactoring.&lt;/p&gt;

&lt;p&gt;Of course you can always use a CMS to model your data and then pull those data into your static site generator to generate your webpage.  However, this adds another level of complexity and cost.  We'll explore how json-ld and the concept of linked data can help make static markdown/yaml files more dynamic.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is json-ld?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://json-ld.org/"&gt;Json-ld&lt;/a&gt; is a linked data format based on json.  If you have never heard of json-ld, that's ok.  The most important thing to know is that it's just plain old json with a few extra special fields.  It's also a w3c standard and you can check out the &lt;a href="https://www.w3.org/TR/json-ld11/"&gt;complete spec&lt;/a&gt;.  We don't really need to understand the whole spec, we're just interested in the way json-ld can reference other data fragments with a url using the keyword "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;
"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;My blogpost&lt;/span&gt;
&lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2021-10-17&lt;/span&gt;
&lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;@id"&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://example.com/author/johnsmith.yml     // @id is json-ld's way of referencing another data fragment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using json-ld over json
&lt;/h2&gt;

&lt;p&gt;Since json-ld is just json, it means you can also use it in a markdown or yaml file.  Now all of a sudden, static markdown and yaml files that's so prevalent in static site generators are not so static anymore.  It can join with other data fragments without a database or CMS.  You just need a client side json-ld processor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sambal.dev"&gt;Sambal&lt;/a&gt; is a static site generator that natively supports schema.org json-ld as the content model.  &lt;a href="https://sambal.dev/docs/get-started/"&gt;Get started&lt;/a&gt; to discover the power of linked data.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>staticsitegenerator</category>
    </item>
    <item>
      <title>Schema.org json-ld static site generator</title>
      <dc:creator>chen4119</dc:creator>
      <pubDate>Sun, 10 Oct 2021 16:04:59 +0000</pubDate>
      <link>https://dev.to/chen4119/schema-org-json-ld-static-site-generator-2pfa</link>
      <guid>https://dev.to/chen4119/schema-org-json-ld-static-site-generator-2pfa</guid>
      <description>&lt;p&gt;&lt;a href="https://sambal.dev"&gt;Sambal&lt;/a&gt; natively supports &lt;a href="https://schema.org/"&gt;schema.org&lt;/a&gt; &lt;a href="https://json-ld.org/"&gt;json-ld&lt;/a&gt; as the content model so you can render webpage directly from any schema.org json-ld data.  By using the open and well known schema.org vocabularies to structure your content from day one, it saves you the trouble of modeling your own content and later realizing it's not compatible with anyone else's content.&lt;/p&gt;

&lt;p&gt;Take the simple example of a blogpost which contains an author, a timestamp, some tags, and the content of the post.  However, without standardizing on schema.org vocabularies, there are literally hundreds of ways you can encode a blogpost.  Tag can be category, title can be header, summary can be description, etc.  This inconsistency in data schema is a big problem that hasn't really been addressed.  It's the reason why it's so hard to switch from one theme to another or one static site generator to another when building a website.  Everybody uses their own flavor of content model even when the content is as simple as a blogpost.&lt;/p&gt;

&lt;p&gt;Schema.org has over 700+ content types and most importantly, it's supported by all the big search engines like Google and Microsoft.  It's the ideal content model for the vast majority of websites.&lt;/p&gt;

&lt;p&gt;It's also fair to ask, then why introduce a completely new static site generator?  You can use schema.org with existing static site generators too.  Yes, but existing static site generators do not fully leverage the power of linked data.  Schema.org json-ld can reference other pieces of data with a uri, similiar to how a hyperlink links to another webpage.  This allows you to do some pretty awesome things that plain old json/yaml data can't.  To illustrate what linked data can do, let's start with a simple markdown file for a blogpost that you commonly see.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;headline&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;My first blog post&lt;/span&gt;
&lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Blue Devil&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;blue.devil@email.com&lt;/span&gt;
&lt;span class="na"&gt;publisher&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Blog Publisher&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;streetAddress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;125 Science Drive&lt;/span&gt;
    &lt;span class="na"&gt;addressLocality&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Durham&lt;/span&gt;
    &lt;span class="na"&gt;addressRegion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;NC&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
Content of my post
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This blogpost contains some data about the author and publisher but once you start having multiple blogposts by the same author and publisher, you'll need to duplicate the data in every markdown file.  There is no standard way to normalize the data in static json/yaml like you can with a database.  In json-ld format though, you can!  Data fragments can be stored anywhere online as long as it has a resolvable URL.  You can simply reference the data using the special "&lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;
" keyword like such&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="p"&gt;--------&lt;/span&gt;
headline: My first blog post
author:
  "@id": https://author.com/bluedevil
publisher:
&lt;span class="gh"&gt;  "@id": https://organization.com/blogpublisher
--------
&lt;/span&gt;Content of my post
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can fetch author and publisher data directly from source and never worry about data becoming stale.  Sambal recursively hydrate json-ld data by automatically resolving all &lt;a class="mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;
 urls.  A url doesn't necessary need to be a https:// either.  It can be a AWS s3:// url, ipfs:// url, or pretty much any protocol.  Sambal provides an easy way to customize how to resolve any url.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sambal.dev/docs/get-started/"&gt;Get started&lt;/a&gt; with Sambal to build your linked data &lt;a href="https://jamstack.org/"&gt;JAMstack&lt;/a&gt; website.&lt;/p&gt;

</description>
      <category>seo</category>
      <category>staticsitegenerator</category>
      <category>webdev</category>
      <category>jsonld</category>
    </item>
  </channel>
</rss>
