Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to separate a large html file into three smaller html files? [closed]

I have a very large website, and I was wondering how to separate a single HTML file into 3 separate HTML files. In order, to organize the code as individual components of a whole like this:

Header.html

Body.html

Footer.html

How can I break the html code into three separate html files but still make them work together as a whole?

like image 528
ChosenJuan Avatar asked Nov 05 '15 17:11

ChosenJuan


People also ask

How do you split a large file in HTML?

Open an HTML file. Position your cursor anywhere between the <BODY> start and end tags of the file, at the location where you want to create the new topic. On the Edit menu, click Split File. In the New HTML file name box, type a name for the new file.

How do I open a big HTML file in my browser?

You can use lynx which is a text based browser to view a large html file. I have a 139M html file and I was able to view it very easily using lynx . lynx divides the entire document into pages and is able to load any given page very quickly.

What should you write at the beginning of an HTML page so that the browser understands that HTML5 is used to display the Web page?

DOCTYPE html> tag is required for HTML5 and should always be the very first thing in your HTML document. This helps the browser know which version of HTML you're using.


2 Answers

A straightforward method would be to use PHP to concatenate 3 includes:

Step 1) In your .htaccess file, enable your server to parse .html & .htm files as .php files:

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .html .htm

Step 2) In page.html, write (only) the following:

<?php

include '/home/example/public_html/header.html';
include '/home/example/public_html/body.html';
include '/home/example/public_html/footer.html';

?>

N.B. /home/example/public_html/ is an example relative-to-root server path. You'll need to change this to whatever your own relative-to-root server path is.

Now, when you point your browser at page.html, your server will parse that .html file as a .php file and concatenate and deliver three separate PHP server-side include files as a single .html file.

like image 180
Rounin - Glory to UKRAINE Avatar answered Sep 27 '22 23:09

Rounin - Glory to UKRAINE


I'm assuming that you're dead-set on static html code in my answer. The answers on switching to dynamic pages are far better.

That said, if I've understood your question, you're looking for something like this:

http://webcomponents.org/articles/introduction-to-html-imports/

like image 31
John Thow Avatar answered Sep 27 '22 23:09

John Thow