You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
Recent Posts
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- The Real State of JavaScript 2018
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
Making Ionic4 SEO Friendly
written by Jeff DelaneyHealth Check: This lesson was last reviewed on and tested with these packages:
- Ionic4 v6
Find an issue? Let's fix it
Ionic 4 is a single page application on the web. All routing is handled clientside, which makes it difficult for some search engines to follow links and render dynamic content.
Linkbots that display social media tags - such as Slack, Facebook, and Twitter - will not parse any JavaScript on the page. You will need to implement server-side rendering (SSR) to have your content rendered by these bots.
Google Search will parse and index JavaScript apps like Ionic and Angular. You do not need SSR to get content rich pages picked up by search
Build an SEO Service
Content rich sites should have a unique title for each page and possibly metatags that can be read by social media cards like Twitter, Facebook, Slack, etc. Let’s create a service that will allow us update this data on any page consistently.
ionic generate service seo |
For now, we will have our service update the title
and set some metatags for a Twitter Card.
import { Injectable } from '@angular/core'; |
Set Metatags on Ionic Pages
Now we can inject the SEO service into any Ionic page and render the title and tags with just a few arguments.
|
Options for SSR
At this point, serverside rendering of an Ionic a challenge. The shadow DOM is not easily parsed to plain HTML, so using something like Puppeteer will not work out of the box. Prerendering web components in Stencil is currently possible, so there’s a good chance we will see solid SSR options for Ionic in the future.