Mobile app version of vmapp.org
Login or Join
Berumen354

: SEO for importing the page header with JavaScript rather than PHP My website has the same header/sidebar/footer on every page, so I have been importing them using PHP. To do this I forced all

@Berumen354

Posted in: #Html #Javascript #Php #Seo

My website has the same header/sidebar/footer on every page, so I have been importing them using PHP. To do this I forced all html files to be processed through the apache servers PHP handler via htaccess. I have come to understand that is not necessarily the best thing to do and so found out how to do everything I need using simple JavaScript. I also store a variable in the initial page that then gets used in the imported html.

Questions: By switching from:

<?php include "_header.html";?>


to

<script type="text/javascript" src="_header.js"></script>


I am noticing that the "view source" shows the header.js link, whereas the PHP method will show the source as if the html had been there all along. Will search engines recognize the html in the JavaScript just as they would when loaded with PHP?

I understand it is bad practice to alter the page contents -after- it is downloaded, but this doesn't fall into that category does it? That would detail things like after a wait function, or after user interaction, correct?

Are there any other foreseeable downfalls to switching to JavaScript and turning off the forced PHP processing?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Berumen354

1 Comments

Sorted by latest first Latest Oldest Best

 

@Speyer207

You should use the php method. PHP is processed on the server, so the full page layout is put together before it is sent to the browser. JavaScript is run in the browser once the rest of the page has loaded.

So with your JavaScript method, there is a chance that the page will be shown to the user before the header has been inserted.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme