Use multiple html pages or show/hide divs with javascript

First of all, I have a background in C (++), Java, MATLAB and Python, mainly used for scientific and electronic applications (Math operation on data, reading data from sensors, microcontrollers). But i'm relatively new to both HTML (CSS) and Javascript. For both I've read some books. In HTML books, multiple pages are done by links (<a></a>).

In javascript (which feels a lot more natural to me than HTML), I've seen some examples where there is only 1 html page, full of divs, who are shown and hiden each time a certain page needs to be shown. This is done with the Jquery command $('#div1').hide() and $('#div2').show();

Now my question is, what is the best practice? When is it better to have multiple HTML pages, and when is it better to have just hide/show divs with Javascript?

Thanks

Answers 1

  • Let me point out that there is no "best practice" to the question that you are asking. It is entirely up to the team if they want to push all the content in one page or keep them separately.

    If in case you have a content that requires decent amount of images to be loaded, or contents that you are sure will rarely be seen, you might want to keep them in separate pages so as to make the page load faster.

    If you have heavy contents which requires a lot of interaction with javascript/jQuery then you certainly might want to keep them in separate pages so that later when you want to debug/add to the code it can be easily done.

    The vice versa of the above holds true as well. If in case you just have small content, or simple text content then you can easily do it in a single page.


Related Articles