Server Side Partials

1 year ago by giacholari

I just came across partials the other day and realized how helpful they could prove to be. In this site, on the photos page, I have utilized this very technique to fetch the photos using a partial view instead of serving the whole HTML page in one go with all the data. This works by fetching the initial HTML document with the container for the data - in this case, the photos container, and then utilizing JavaScript I fetch the rest of the HTML with the photos and I inject it within the container. This could be very powerful when searching. You could query the data and swap the content on the page instead of rerendering the whole page which will lead to unnecessary assets being downloaded and lead to increased bandwidth and maintenance costs. The point being is that you do not need a JavaScript framework do achieve this - plain old school JavaScript would do the job.