The website is redesigned and converted to AMP

Apr 29, 2020

At the end of last July, I laid out the path I was going to take to further improve the website. I wanted a design that has Material features, is very compact, and possibly doesn’t even have any JavaScript. I determined that only the menu open / close functionality and the carousel on the landing page were using some JavaScript. The menu could possibly operate in a CSS-only manner, and maybe even the carousel too.

Let’s look at the CSS side: a lot of libraries have extensive features I won’t need. Modern libraries have a main scss file that pulls in all the components feature by feature. I was combing through Material Components for the web, cutting off as much meat as I could. The work was overwhelming and I was always thinking there should be a leaner and cleaner solution. Then, during my journey, I came across AMP and realized that many of its requirements align with my goals:

  1. It aims to minimize fluff by essentially eliminating custom JavaScript, which makes it easier not to include any frivolous code. Note: with amp-script there is a way now to add custom JavaScript, but it cannot be more than 150 KB, and it is executed in a worker thread, and it has API limitations.
  2. It enforces a hard limit on custom CSS styles as well: 50 KB maximum. This inspires anyone to be lean.
  3. When your site is served from the AMP cache, the Google Analytics data will appear in your analytics statistics, so you won’t lose anything.
  4. There’s still a way to supply dynamic content like Disqus blog post comments (a feature I already had for my blog posts).

Additional gains:

  • Google will cache your pages and help serve them with its world-class CDN network.
  • If you structure your page properly and provide specific metadata, Google will also present search results in an enhanced way.

Possible downsides:

  • The lack of custom JavaScript may hurt some. If your site is not static and you need to have forms or other custom code, you have two choices:
    1. You can develop an AMP version of your pages while you can keep serving the enriched version through your own hosting system/service.
    2. Utilize amp-script and amp-form if the limitations are acceptable for you.
  • When your page is served from the cache, Google will clearly reveal that it is coming from the cdn.ampproject.org domain or www.google.com. I can see that this could confuse the web page reader and may annoy some people. There’s a way to overcome this domain issue with the help of Signed HTTP Exchanges. If you serve your website from your own back-end, this requires some technical knowledge and heavy lifting to accomplish. Cloudflare offers AMP Real URL, which uses the Signed Exchanges (SXG) browser feature to provide the exact same URL for both the AMP-cached and the self-hosted instances of your pages. SXG is currently only fully embraced by Chrome and Android browsers.

I’ll try to summarize what steps I took to arrive at the current design:

  • I yanked out all CSS and JavaScript from the website.
  • I started to identify which AMP components I would use.
  • For custom CSS, I first used an AMP version of the Surface CSS framework. That provided Material design elements while being compact. However, I yanked Surface AMP’s grid system and replaced it with Bootstrap 4’s superior CSS Flex-based grid system.
  • After that, I yanked out parts I was not using, like forms, tabs, and modals.
  • I applied my unique color scheme to my SCSS.
  • While restructuring, I took advantage of the cards Material design element. This provides a white background for most of the text, which in turn results in better contrast for reading. The font color got darker as well, to increase the contrast. The contrast issue had been detected by an accessibility test before, so I was happy to improve on this.
  • I also needed some fine-tuning, like only applying Surface’s ol- and ul-related rules for menus.
  • I also had to customize the styling of amp-menu, amp-sidebar, and other parts of the website.
  • I also transitioned to SCSS and integrated that into the build pipeline. First, I started massaging a custom Grunt build script for the SCSS -> CSS -> minify operations. But after some research, I realized that scssify can transform my scss into css without any extra Ruby gems, and the sass style: compressed option in _config.yml will automatically minify it as well, also without any extra Ruby gems. All this without needing any grunt babel build script. That’s very neat because even Jekyll hosting providers will support that, and I won’t have to run my own scripts. I just wish I had discovered scssify and sass compress earlier.
  • I decided not to go with my own menu, but to embrace amp-sidebar. Only some portion of it can be presented horizontally as a menu (this is called the toolbar). While I could have hidden the sidebar and the hamburger button at large resolutions, I decided never to hide them, so the user can decide which menu to use. The sidebar has social sharing buttons and some extra menus.
  • I went through several iterations to convert the Bootstrap carousel to amp-carousel. That’s only used on the landing page. I haven’t been able to revive the captions for the carousel slides yet, but maybe I’ll leave them that way. The captions were kind of weird anyway: I had to add a text shadow to increase the contrast compared to the slide image at all resolutions (the captions can fall onto different color sections of the slide at different resolutions).
  • I needed to convert the Google Analytics bits and pieces to the AMP version.
  • I paid attention to load the amp-carousel on the landing page and the Disqus AMP for blog post pages only. The AMP verifier helps point out if you include something you don’t actually use.
  • I made size optimizations wherever I could, like even shortening my custom-hosted font filenames.
  • I converted the Disqus forums to AMP versions. That’s not an easy feat: you have to set up a separate custom domain which hosts a portion of JavaScript that your site will pull in. Fortunately, I could use free gh-pages hosting for this, but at first I had trouble adding the second domain to my Disqus administration, so I almost thought I’d have to partially sacrifice my csaba.dev domain for this. I was somewhat hesitant, because people reported that Disqus generates a lot of requests and traffic, but for now I stayed with Disqus. I’m not sure if a rival service would generate less traffic, by the way.
  • If I wanted to use the Disqus counter, I also had to generate the SHA-384 fingerprint of the pulled-in script (related to the counter) and add it to my site’s header meta tags. Note that the regular comment section has a counter as well, so currently I don’t integrate the separate counter, trying to keep the commenting feature as lean as possible.

The big question is: did the numbers improve? How does the new Material / AMP version fare in Lighthouse tests? I certainly don’t have JavaScript now (apart from AMP’s), and have less than 30 KB of CSS, but AMP brings in some scripts and styles. I’ll analyze that in my next post.

Comments loading...