Since Mozilla doesn’t support HTML import and I guess we have to enable it explicitly from some where, is it still a good idea to use HTML import to include external HTML files in the main HTML file?
I am just trying to figuring out what’s the best way to include an external HTML file inside a HTML file since my code is growing faster.
If HTML import is not a good way to go, could anyone please suggest another efficient way to accomplish this?
One way to include things like an external file in an html page is to rename the file extension to .shtml and use Server Side Includes (SSI) in the html.
This was the standard method before PHP became common.
Please mind that the external file to be included, SSI, PHP or whatever, should only consist of the code that would be in that place as a part of the html. The file with the SSI command must have the shtml extension, but the file to be included could have any extension you like though most people use html so the file can be viewed by its own,
(Please don’t mix up includes with frames/iframes where a complete html file is displayed but not a part of the html that contains the frame only.)
Doing things server side should be more robust, being browser agnostic.
PHP is freely available and offered as standard by most hosts.
It can be used for things as simple as basic includes, but will also offer the ability it include a little logic too, or a whole world of possibilities beyond that as the site grows and your needs become more complex.
Thanks. I believe I would not be able to test this approach locally? Do you think there’s something more modern that I could use.
Actually, I converted all PHP files recently to HTML and looking for a way to include the external files just like PHP has include function. I would prefer not to go to something which was used before PHP arrived.
Thanks. Actually, I am not planning to use any server side related thing, hence SHTML wouldn’t be a good option for me as well. I believe, I would have to use the jQuery load everytime I have to use external HTML as mentioned in the post below:
JS seems a strange choice for including a file in another. It could well give users a jumpy experience as the included file is actually loaded. And what about users who have disabled JS?
Thanks again. Your answer does answers my question. When I say “to include HTML file from somewhere else”, I mean from different directory and not somewhere else from the web. Sorry about the confusion.
That’s where I was thinking of using the jQuery load method as explained in the post I shared above. Thanks