rafgraph / spa-github-pages

Host single page apps with GitHub Pages
https://spa-github-pages.rafgraph.dev
MIT License
3.85k stars 567 forks source link

Why don't just make 404.html a copy of index.html? #30

Closed bpceee closed 5 years ago

bpceee commented 5 years ago

Brilliant! But making 404.html a copy of index.html also works. What's the benefits of this repo? SEO friendly? Did I miss something?

johnss commented 5 years ago

Quoted from readme.md

A quick SEO note - while it's never good to have a 404 response, it appears based on Search Engine Land's testing that Google's crawler will treat the JavaScript window.location redirect in the 404.html file the same as a 301 redirect for its indexing. From my testing I can confirm that Google will index all pages without issue, the only caveat is that the redirect query is what Google indexes as the url. For example, the url example.tld/about will get indexed as example.tld/?p=/about. When the user clicks on the search result, the url will change back to example.tld/about once the site loads.

404.html is intended to be used for not found error not for routing SPA so it will return 404 and search engine usually will not index error page (4xx & 5xx), but will crawl, follow redirect and indexing the redirected pages if not returning error response header, 404.html using window.location for redirecting to actual page without 404 response header

bpceee commented 5 years ago

@johnss Thanks a lot! Good to know.