Logo

dev-resources.site

for different kinds of informations.

WhatsApp link preview is weird

Published at
12/4/2019
Categories
preview
gatsby
site
opengraph
Author
lucis
Categories
4 categories in total
preview
open
gatsby
open
site
open
opengraph
open
Author
5 person written this
lucis
open
WhatsApp link preview is weird

So, my day as a web developer today was described by this image:
My day as a dev

As it may not be so easy to understand, I was testing the link preview feature of Whatsapp for a website I've been developing. Being a real fan of using the preview (and waiting a couple of seconds after I paste some article's URL on my IM's), I was very determined to make it work for this site in particular, but for some reason unknown to me it was not. I was adding the correct meta tags using OpenGraph and it was working flawlessly on Facebook, Twitter, and Telegram. But not Whatsapp.

I've searched everywhere for this problem: SOF, react-helmet's Github, Gatsby.js community... And every little thing I would change, trying to make it work, would need another deploy so it took a while. After a lot of "solutions" that included changing the image dimensions, adding a second tag and making the title a bit shorter, I've come across a tiny SOF comment that didn't have any upvote and would comment about WhatsApp not liking style tags before the meta tags. At first I didn't give it any credit, as it was improbable and difficult to try, since Gatsby is the one that builds the final index.html.

But eventually, after a lot of frustration, I had to try this last solution. This time, I changed the built code produced by Gatsby putting the meta tags just after the beginning of the head section. Deployed the files to a temporary now.sh site and gave it a try. It worked.

I was just as happy as I was shocked. This is the kind of implementation detail that you SHOULD disclose to developers.

After all, it was the tachyons library that I've included directly on my custom CSS and it took some space. After removing it and replacing it by a CDN, it started working. It's valid to say that after removing tachyons, some other CSS was still included before the meta tags, so the problem was actually the size of the CSS inside the style tag.

edit: Vitor Oliveira has pointed out another great way of solving this problem: Sorting the head tags with the meta data first. For this, you need to edit (or add) a gatsby-ssr.js exporting the following function:



export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
  const headComponents = getHeadComponents();
  headComponents.sort((a, b) => {
    if (a.type === 'meta') {
      return -1;
    } else if (b.type === 'meta') {
      return 1;
    }
    return 0;
  });
  replaceHeadComponents(headComponents);
};


Enter fullscreen mode Exit fullscreen mode
site Article's
29 articles in total
Favicon
How to Launch and Grow a New Website Quickly: A Proven Case Study
Favicon
What can I do to enhance my site's ranking in Japan?
Favicon
Creating a Stunning WordPress Site from Scratch
Favicon
Astro vs Visual Studio 2022 as Static Site Generators
Favicon
Revolutionizing Mining Operations: The Power of Mine Site Technologies
Favicon
Cool site
Favicon
Hosting static sites with Cloudflare R2 and MinIO Client
Favicon
Cursos que formaram meu caráter: Desenvolvimento web com Quarkus - Saudades do Maven, relatórios com Project-report
Favicon
Are you looking for a professional moving service?
Favicon
Search the hospitals using Huawei Map Kit, Site Kit and Location Kit in Patient Tracking Android app (Kotlin) – Part 5
Favicon
What is Digital Signage?
Favicon
A Guide to Azure Site Recovery - Part 2
Favicon
Hello, World
Favicon
Como contratar editores de áudio e vídeo e os benefícios para a expansão do seu negócio
Favicon
Migrando (e customizando) o tema desse site (WIP)
Favicon
Caileak APK: Best Platform to Download APK
Favicon
Full Site Editing (FSE) - All You Need To Know - P1 - Overview
Favicon
Active Directory Kavramları ve Site Yapısı
Favicon
Acessibilidade na Internet
Favicon
The perfect way to check programming language documentation
Favicon
Note: Tweaking my tools
Favicon
Note: testing a thing
Favicon
How to build a docs site
Favicon
WhatsApp link preview is weird
Favicon
How To Get a Comment Section On Your Static Site
Favicon
Construindo meu novo site com UIKit, Jus e CuboHub
Favicon
Nginx : 2 domínios (dns) no mesmo servidor
Favicon
Is their any API where I could get all my posts from the site?
Favicon
Back to static site

Featured ones: