1

Let's say I am creating a webapp for a library. My base url is http://mylibrary.com. I want to use "pretty" URLs as follows:

  1. http://mylibrary.com/books (list all books)
  2. http://mylibrary.com/books/book1 (details of a particular book)

At present my approach is to create a single page app and use history api to manage the URLs. i.e I load all CSS and JS files when the user visits the home page. From then I just get data from server using AJAX, in JSON format and then create the required HTML using Javascript.

But I have learnt that this is not so good from SEO point of view.If a crawler were to visit http://mylibrary.com/books it will not see booklist at all because AJAX calls would not take place.

My question is what is the other approach to design this kind of app ? Specifically:

  1. Should the server create entire web page and send it to browser? I mean will the response from server include everything from <html> to </html> or only the required parts?
  2. Do programming languages like PHP efficiently manage to send the HTML to clients ? I would rather have the webserver do it ..
  3. It appears to me that in this scenario AJAX would have very little role to play other than may be change minor parts of the page. Is that a correct understanding ? ..and here I was thinking AJAX is the modern way of doing things
dbugger
  • 15,868
  • 9
  • 31
  • 33
everydayapps
  • 455
  • 1
  • 5
  • 20

1 Answers1

2

A library would have many books. So the list would be long..

Using ajax allows you to fetch only the part of it the user is trying to read, without having to retrieve the entire list, or navigate by reloading.

so for low bandwidth, and impatient users, ajax is a godsend. for crawlers that need the entire page to collect data from, not so much..

so really you want to provide different content depending on the visistor. How to identify web-crawler?

IMHO: Provide the page from php, if the user agent is a robot, provide the list, otherwise provide the fancy ajax based site, that shows only what you want, when you want..

Community
  • 1
  • 1
Henrik
  • 2,180
  • 16
  • 29