user1163859
user1163859

Reputation: 123

PHP/HTML: Code reuse

How does Stackoverflow reuse their code, especially the header and footer?

So, basically when i click on 'Tags' only the content changes, not the header and footer. What are the best pratises? A link to a simple tutorial would be good.

I'm using HTML5, PHP, and MySQL. No javascript involved yet.

Upvotes: 1

Views: 3452

Answers (4)

vzwick
vzwick

Reputation: 11064

With no framework whatsoever involved, try something along these lines:

<?php

include('header.php');

// do something, render page specific content ...

include('footer.php');

Upvotes: 4

pwittke
pwittke

Reputation: 17

I dont know if its possible with HTML5, but I use AJAX and JQUERY for a dynamic site/content refresh

the Jquery Documentation is to find at http://docs.jquery.com/Main_Page and for the JqueryUI at http://jqueryui.com/demos/

here is a simple JQUERY/AJAX code snippet

$.ajax({
    beforeSend:function()   {
        $("#loader").show();
    },
    url:your/path/file.php,
    method:"get",
    data:{rights:usrRights,rights2:usrRights2},
    dataType:"html",
    success:function(output)    {
        $("#content").html(output);
    },
    complete: function() {
        $("#loader").fadeOut("slow");
    }
});

included a loader div with an overlay and by default its hidden in the div i put a .gif loader image

hope I could help you

regards

Upvotes: 0

Janis Peisenieks
Janis Peisenieks

Reputation: 4998

The way they do it is by separating all of the static content ( the one that wouldn't change between pages) into seperate files. Then they include them by demand as @vzwick pointed out.

It must be said, that they ARE loaded. SO is not using AJAX to reload only specific parts of the page for layout purposes. The header and footer parts are cached in between server calls, and seem to load almost instantaniously.

This is the principle that most of web-scripting languages work upon.

Upvotes: 1

Evgenij Reznik
Evgenij Reznik

Reputation: 18614

Ajax is a technology to reload only particular divs, not the whole page: Ajax

Upvotes: 0

Related Questions