Skip to content

sharjeel619/spa-seo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SEO solution for your Single page application

Problem

You have a SPA and you want to put dynamic information (most likely from an API call) in HTML meta tags, so that when you share a particular link from your SPA website on some social media, it displays all the relevant information.

Solution

  • A browser requests your single page application from the server, which is going to be loaded from a single index.html file.
  • You program some intermediary server code which intercepts the client request and differentiates whether the request came from a browser or some social media bot.
  • If the request came from some social media bot, make an API call to your back-end server, gather the data you need, fill in that data to html meta tags and return those tags in string format back to the client.
  • If the request didn't come from some social media bot, then simply return the index.html file from the build folder of your single page application.

Installation

yarn install && node index.js

This will install your Node dependencies and start a local Node server at port 9999.

I've already build some files from a simple Vue.js app in the dist folder. Or you can simply use your own. Link to the sample Vue.js app can be found here

Usage

  • Go to localhost:9999 in your browser and you will see your SPA load.
  • To see if the SEO actually works, you don't need an actual node.js server you can just fire up a ngrok server that you can download from here
  • Click on one of the tv shows and copy/paste the ngrok generated url (e.g: 'your_ngrok_url/tvshow/2') in your twitter/linkedin post or slack/discord channel
  • Working link for this project on Cyclic.sh can be found here
  • And Voila! you should all the relevant details in your post. Twitter LinkedIn Discord Slack

Setting up with NgRock

  • Login/Signup to ngrok.com and copy your authtoken from https://dashboard.ngrok.com/get-started/setup and paste it in your ngrok terminal like so ./ngrok authtoken your_ngrok_token
  • Then type ngrok http 9999 -host-header="localhost:9999" in the ngrok terminal. This command will expose your local server to a public url.
  • Copy/Paste the url generated by ngrok terminal in your browser and you should see your SPA load.

Releases

No releases published

Packages

No packages published