问题原文
原帖链接 · Kyle Postlewait · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · Jeff Taylor · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
