Matt
Matt

Reputation: 285

Can you create a complete website with only one page?

Can you create a complete website with only one page?

So using XHTML, CSS, and JavaScript. You can change the content and structure of a web page. Could you build a website (that would normally have multiple pages), but instead bundle it all into one page essentially, and use JavaScript to change the structure and content of the web page so drastically that it essentially is a new page of information?

Could you let the browser open an initial set of information the browser would show, and then use Ajax to load the rest of the information to display the rest of the web pages. Is this practical?

Upvotes: 1

Views: 1476

Answers (5)

Hidde
Hidde

Reputation: 11931

Definitely, yes. Just try it out!

Upvotes: 1

Glenn Dayton
Glenn Dayton

Reputation: 1430

Entirely possible BUT bad idea for accessibility reasons. If someone has turned off Javascript they will not be able to view the multiple pages to the single page website. I would recommend that you build the site using PHP. You can implement the same "one-page" idea, but using the include function with .inc files. To get the multiple page effect all you have to do is change variables in the URL. For example:

http://www.example.com/index.php             <- index
http://www.example.com/index.php?page=faq    <- FAQs
http://www.example.com/index.php?page=login  <- login
...

Just changing the $_REQUEST variable page with a new string would allow you to render multiple pages. The PHP code that would allow you to do this would look something like this:

<?php
...
$page = $_REQUEST['page'];
if(isset($page)){
    if(file_exists($page.".inc"))
        include($page.".inc");
    else
        echo "Page does not exist. Try Again.";
else
    include('main.inc');
...
?>

Contained within the various .inc files would be your HTML code corresponding to the various pages of the website.

Upvotes: -1

Cynthia
Cynthia

Reputation: 5403

You can do it, but why would you want to? It would kill any attempt at good SEO.

Upvotes: 0

Eric J.
Eric J.

Reputation: 150108

Yes, using Ajax.

In fact, this is an application type (Singe Page App) specifically supported by Microsoft's ASP.Net MVC 4.

Upvotes: 1

Justin Blank
Justin Blank

Reputation: 1878

Yes, of course. One way to do it is with something like backbone.js. It wants to communicate with a server-side RESTful API by default, but it can also use html5 storage, which is what its example todo app does.

Upvotes: 1

Related Questions