Build a normal site. Give each page a normal URL. Let Google index those URLs. If you don't have pages for Google to index, that it can't index your content.
Progressively enhance the site with JS/Ajax.
When a link is followed (or other action that, without JS, would load a new page is performed) use JavaScript to transform the current page into the target page.
Use pushState
to change the URL to the URL that would have been loaded if you were not using JavaScript. (Do this instead of using the fragment identifer (#
) hack).
Make sure you listen for history events so you can transform the page back when the back button is clicked.
This results in situations such as:
- User arrives at
/foo
from Google /foo
contains all the content for the/foo
page- User clicks link to
/bar
- JavaScript changes the content of the page to match what the user would have got from going to
/bar
directly and sets URL to/bar
withpushState
Note that there is also the (not recommended) hashbang technique which hacks a one-page site into a form that Google can index, but which is not robust, doesn't work for any other non-JS client and is almost as much work as doing things properly.