0

I have React web app. It's a single page app, so there's basically an "empty" HTML file with a JS bundle that does it all.

But to improve SEO capabilities, I'm doing SSR for robot crawlers on my server. I also differentiate "desktop" crawlers from "mobile" crawlers and render different layouts for each one of them.

I differentiate users and robots by their User-Agent string.

So these are the possibilities:

REGULAR USER  => GETS "EMPTY" HTML + JS BUNDLE
ROBOT DESKTOP => GETS RENDERED HTML WITH DESKTOP LAYOUT
ROBOT MOBILE  => GETS RENDERED HTML WITH MOBILE LAYOUT 

I'm pretty sure that I need to include a res.set("Vary","User-Agent"); header.

But should I add it to all responses or just to the SSR responses that are served to the robots?

2

As far as I know Vary header is used for displaying website content via CSS or HTML appropriately for the User Agent who is accessing the site, right? So if your SPA also have different serve between mobile and desktop, you need Vary header for all responses.

BTW, SSR not better in SEO, SSR and SPA now is same rank(just depend on the page content/meta), because search engine use webbrowser-like to fetch/crawl the page. Even the HTML is empty google will scrape all page content that generated using JS. The most important thing is just the routing. You should change URL if open new link and you should go to the destination page if open the link from new browser.

references:

1
  • Thanks. This is good to know, even though I'm not ready to trust Googlebot to render my app. Also, I know that not all robots will render the JS content. – cbdeveloper Jan 7 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.