Git Product home page Git Product logo

spa-seo's Introduction

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.

spa-seo's People

Contributors

sharjeel619 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

spa-seo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.