简体   繁体   中英

Is Adding the Doctype at the top of the header file enough or does it need to be on top of every html file?

I have been using a shopping cart script for a few years now and it is open source, so that I can change the code, or the layout if I want to.

Now, the main structure of a general page is like this.

Index.php - which contains a some php information and then gets the layout from other html files via the include page option.

To clarify, all the php info is in that file, but the layout for the header, footer and general content all get collected from other files, I am guessing to save work.

Now the header.html file is the only that contains the doctype at the top of the file, the rest just start displaying the code.

My question is: is displaying the code the doctype in the header file enough, since the 2 or more files get send to the browser with the doctype placed in the header, it is displayed there. Or would every html file need a doctype, because they get read first, before they get merged into what the client sees?

I know php is a server side operation, but html get read as they are - so I am just wondering if that will create confusion for the different browsers??

Cheers Jeff

Yes, it only needs to be in the header file. The .php files are separate, yes, but index.php concatenates them into one file.

The browser doesn't even know there are 3 files. It just sees the single HTML file joined by index.php, and that file just needs the one doctype declaration at the top.

The only thing that is needed is a doctype as the very first line in the HTML which gets sent to the browser. PHP will combine everything together prior to sending it to the browser so only the header should need the doctype.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM