SEO for Web Developers
Tags: webdev, performance
Published: 2022-07-02 16:53:14

Search Engine Optimisation is usually a skill that is reserved for those in Digital Marketing, but I think that as a web developer, having competency in SEO is a valuable assest to have to differentiate yourself and display a bit more versatility.

## What is SEO?

> SEO (Search Engine Optimization) is the practice of optimizing a website or webpage to increase the quantity and quality of its traffic from a search engine’s organic results.[[1](https://ahrefs.com/blog/what-is-seo/)]

There is a technical aspect behind SEO that web developers should have a basic understanding of, where measures are implemented to optimise the website/server so that search engines can easily crawl, index and then rank the website. 

If you create an amazing site with great content but search engines struggle to index it, all that effort will be in vain.

---

## Key habits that should be followed

- Make sure that all images have alt tags, as alt tags will provide search engines with a better context/description of what the image is, allowing them to index it properly.
- When linking to another URL, words should be separated by hypens `'-'` rather than underscores `'_'` as search engines read hypens as a space.
- Try to keep domain names as short as possible while maintaining coherency, a domain with more than 15 characters should be avoided to ensure better readability for humans.
![https://moz.com/blog/15-seo-best-practices-for-structuring-urls](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jx6gc841qf3cbhxpbowm.png)[[2](https://moz.com/blog/15-seo-best-practices-for-structuring-urls)]
- Images should have unique file names that try to describe the content of the image, and you should trying to avoid having duplicates of the same image as this will split the score for this image between each copy.
- 'Lazy-loading' images is a technique used to defer the loading of an image until it enters the viewpoint, instead of loading them upfront.
- Try to prioritise the usage of SVGs and WebPs over PNGs and JPEGs to increase the performance of the page.

> WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG images at equivalent SSIM quality index.[[3](https://developers.google.com/speed/webp)]

---

## What is Lighthouse?
> Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, SEO and more.[[4](https://developer.chrome.com/docs/lighthouse/overview/)]

![https://nooshu.com/blog/2019/08/18/lighthouse-score-100-not-always-for-the-better/](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2dpq74hyg6tnpes4jwfq.png)
 
Google gives higher search page rankings to websites that achieve a higher lighthouse score. With the sheer number of web pages available, Google's crawlers can only spend a certain amount of time scraping your page before moving to the next one. Therefore it is imperative that your page gets a high score to stand out among the rest.

You can use [Measure](https://web.dev/measure/) to test your page in a lab environment and [PageSpeed Insights](https://pagespeed.web.dev/) for field performance

---

## Head component 
The head component of a page will control how your page will appear on search engine results and social media posts.

- The `<title>` element for your homepage can list the name of your website or business, and could include other bits of important information like the physical location of the business or maybe a few of its main focuses or offerings. Try to make the title element brief and unique from other pages.

- A page's meta description tag gives Google and other search engines a summary of what the page is about. Meta description tags are important because Google might use them as snippets for your pages in search engine results.
> Adding meta description tags to each of your pages is always a good practice in case Google cannot find a good selection of text to use in the snippet.[[5](https://developers.google.com/search/docs/beginner/seo-starter-guide)]
Meta descriptions should accurately summarise the content of the page wile also being unique.

- Meta properties that cause a title, description and image to appear when a link to this page is shared on social media (example for Facebook
`<meta name="og:url" content="your-website.com/the-current-page" >
<meta name="og:description" content="Web page description">
<meta name="og:type" content="website">
<meta name="og:description" content="your-website.com/your-image.png">`

---

## Hosting

- Your choice of web hosting provider can have a huge impact on your site, as the load time of your website is an important ranking factor. PageSpeed Insights Speed Score uses two important speed metrics: First Contentful Paint (FCP) and DOMContentLoaded (DCL).
- Location is another factor as choosing a web hosting service with server locations that are geographically close to your operational area so that you can ensure that there will be a naturally-fast server response time for your site. 
- Having a reliable host is important to experience as little downtime as possible Downtime has an immediate effect, as your potential visitors will no longer be able to access the website. In the long term, downtime can increase your bounce rate, and that can take a long time to repair.

> As web pages become more complex, referencing resources from numerous domains, DNS lookups can become a significant bottleneck in the browsing experience. Whenever a client needs to query a DNS resolver over the network, the latency introduced can be significant, depending on the proximity and number of name servers the resolver has to query.[[6](https://developers.google.com/speed/public-dns/docs/performance)]

For example I used Namecheap to purchase a domain and hosting, and their hosting performs poorly and I optimised my site's code as much as I could but never get past 60 on Lighthouse's performance score. However I switched out my DNS name-servers to Cloudflare and saw my site hit 92 afterwards.

---

## What is a CDN?

> A content delivery network (CDN) is a group of geographically distributed servers that speed up the delivery of web content by bringing it closer to where users are. Data centres across the globe use caching, a process that temporarily stores copies of files, so that you can access internet content from a web-enabled device or browser more quickly through a server near you. CDNs cache content like web pages, images, and video in proxy servers near to your physical location.[[7](https://www.akamai.com/our-thinking/cdn/what-is-a-cdn)]

![https://www.cloudflare.com/learning/cdn/what-is-a-cdn/](https://cf-assets.www.cloudflare.com/slt3lc6tev37/540CpDkqSDg6QAPi5nO1AP/b44a3edb5abc4e115ddab9b4d9bf7a32/Learning-How-does-a-CDN-work.svg)
 
Essentially, copies of your site are stored at multiple, geographically diverse data centres so that users have faster and more reliable access to your site.

A CDN can be used to improve site speed and content availability, reduce bandwidth costs and improve site security by mitigating DDoS attacks.

---

## Minimising JS and CSS

Minifying Javascript and CSS files can contribute to help your website load faster. Minification is the process of removing unnecessary characters from code without changing the way that code works. These unnecessary characters are usually things like: white-space characters, new line breaks, comments, block delimiters.

Minifying code can reduce the file size by 30-40%. Sometimes even as much as 50%. Concatenating files also helps reduce the load on your server and network. Combining multiple files into one lets a server send more data in a fewer number of connections.

To minimise your CSS and JS, you could use a tool like [Minifier](https://www.minifier.org/).

For a more advanced minimisation, [PurgeCSS](https://purgecss.com/) which is a tool to remove unused CSS. If you use a CSS framework like Tailwind or Bootstrap, chances are that you are only using a small subset of the framework, and a lot of unnecessary CSS will be included.

If you are a React developer and care about performance, Preact is a lightweight alternative to React that focuses on performance. Preact keeps the same modern API as React. And if that's not enough, there's an extensive compatibility layer with React to make sure your existing React code can be used in Preact. It's called preact/compat. Preact's bundle size is 3kB compared to the minified bundle of react + react-dom size's 128kB.

You can also use [Gzip](https://www.gnu.org/software/gzip/), a software application for file compression, to reduce the size of your CSS, HTML, and JavaScript files that are larger than 150 bytes.

---

## Performance Analysis 

To analyse a page's performance on search engines, tools such as Google's [Search Console](https://search.google.com/search-console) and [Bing Webmaster Tools](https://www.bing.com/toolbox/webmaster) can be utilised. 

With these tools website owners can:
- See which parts of a site had problems crawling
- Test and submit sitemaps
- Analyze or generate robots.txt files
- Remove URLs already crawled
- Specify your preferred domain
- Identify issues with title and description meta tags
- Understand the top searches used to reach a site
- Get a glimpse at how search engines sees pages
- Receive notifications of quality guidelines violations and request a site reconsideration

---

## More SEO Resources
[Google SEO Starter Guide](https://developers.google.com/search/docs/beginner/seo-starter-guide)
[The Indispensable Guide to SEO for Web Developers](https://prerender.io/seo-for-web-developers/)
[The Web Developer's SEO Cheat Sheet](https://moz.com/learn/seo/seo-cheat-sheet)
![https://moz.com/learn/seo/seo-cheat-sheet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw5ye89bwud6coowj6mc.png)