Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Swig seems superfluous in that stack given it already has React, one could just use React to prerender the pages.


He provides his rational towards the bottom of the post:

> But do we really need a separate template for this? Why not just render everything inside the App component? Yes, you could do it, as long as you are okay with invalid HTML markup and not being able to include inline script tags like Google Analytics directly in the App component. But having said that, invalid markup is probably not relevant to SEO anymore and there are workarounds to include inline script tags in React components. So it's up to you, but for the purposes of this tutorial we will be using a Swig template.


I'm not clear on the "invalid markup" portion. Aren't `data-*` attributes valid for all tags in HTML5? Also, if you really don't want them you can render with `React.renderToStaticMarkup`.


Personally, the only things I had to do to prerender full pages with React were:

- prepend '<!DOCTYPE html>' to the resulting HTML

- attribute "prefix" in head tag "<title>" wasn't outputted, so until it's fixed in the library, I just use a data attribute "data-replace-prefix" and removed the extra "data-replace-" from the resulting HTML

-------

Also, he could include inline scripts (like Google Analytics) this way:

  return <script dangerouslySetInnerHTML={{__html: "THE_JS_CODE"}}></script>;




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: