SPA — Prerender.io — AWS S3 How to make it work.

So this post if for all you folks who want to use the goodness that Prerender affords you with AWS’s amazing S3 service in your Single page Application(SPA). The problem is that S3 doesn’t provide any kind of conditional logic which is required to setup prerender. I was struggling with this problem while working with SEATRR and stumbled upon a workable solution.

So let’s break it down into what we need to implement prerender.io

  1. Setup prerender on a server (in my case an EC2 instance) or get an account at prerender.io to use their service.prerender.io end point.
  2. A way to identify the user agent.
  3. Redirect to the Prerender instance.

Step 1 I think most of you have down!

Step 2&3 is where the problem is.

But Apache is pretty good at it. I think you can see where I’m going with this. I propose that you store your main index file on an apache server, but all your assets like Javascript, CSS, HTML templates etc. you keep on the S3 instance. So when your index file loads Apache can perform the identification of the user agent and redirection if required. Else your index.html can load the assets from S3.

Just remember, You’ll have to enable CORS on your S3 bucket to allow loading these resources. Hope this saves you from going bald early like me.. Cheerio!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.