DEV Community

Hunzlah Malik
Hunzlah Malik

Posted on • Updated on

Static site redirector


Don’t you fed-up with the long URLs and sometimes you need to use dynamic URLs in apps. Keeping in mind that we don’t want to use many resources but we need these dynamic and short URLs for sharing and storing. For example, you are making an app and you are providing your website link in it. After some time you changed your website URL and paying for the redirection. Paying?! What!! Noo.

We don't do that here

In this article, I’ll show you the easiest way to make a static site redirector and static means no back-end, only front-end. And only front-end means that we are working on javascript.


  • Github account
  • Basic knowledge of HTML and javascript

Step 1

Create a repository with any name. In this example, I'll be using redirector as my repo name. Create index.html, redirector.js and copy this code in it.

Visit this for latest code.

Replace my github username ghostdart with your in redirector.js. Then the links in the file will be something like this

Enter fullscreen mode Exit fullscreen mode

Step 2

Now create a data.json file in the same repo. And put some data in it like this

    "google": "",
    "elizajs": "",
    "eren" : ""
Enter fullscreen mode Exit fullscreen mode

On left, you can put the small link/name and on right there should be the original link. The javascript will load this file and search for key and value. If found it will be redirected to the original link.

Step 4

Now the last step is to make your site public. Fortunately, the GitHub pages will do that for you in one click. Just go to your repository setting and turn on Github pages.
Github pages
You'll get a notification of your site is public. You can share the short link with others like this.
OR<your key in data.json>
Enter fullscreen mode Exit fullscreen mode

Now everything is done. And in future, if you want to add more links just edit the data.json file and it'll be online 😃

👋 That's All Folks!

If you have any questions feel free to ask me in the comments and I will do my best to answer them. Feel free to read some of my other blogs @ghostdart. Till then, thanks for reading, and happy coding! 😊

Top comments (0)