Don’t use client side includes!

Share this article’s Using Client Side Includes instead of Server Side Includes makes the case for replacing server-side techniques for including common page components with alternatives powered by Javascript. My advice: stay well clear. While Javascript includes may reduce the load on your server slightly and may even increase page loading times due to additional client-side caching, the cons far outweigh the pros:

  • Javascript is a serious accessibility red flag: to meet accessibility requirements your content needs to be accessible for users and devices which lack Javascript support.
  • Search engines can’t see content that is added with Javascript. If you hide your links in Javascript search engine spiders will be unable to even crawl your site.
  • Javascript is cached aggressively by many browsers. This may help performance, but it means that changes you make to your includes may not show up unless visitors force-refresh their browsers. You can’t expect them to do that very often, if ever.
  • The performance hit of enabling SSIs is usually greatly over-stated. Modern web servers are usually hugely powerful machines. Many sites dynamically generate every page using technologies such as PHP or Perl, which carry far higher overheads than simple SSIs.

If your host doesn’t support some form of server side include, you should move to another host. The hosting market is saturated these days and good quality hosting with all the frills for a moderately trafficed site shouldn’t set you back more than five or ten dollars a month. Note that that’s assuming you go with an open source platform; proprietary hosting platforms can cost quite a bit more.

The only case when Javascript includes might make sense is if you are distributing a site on a CD where a dynamic serving platform is not available, but even then a better solution would be to generate the static HTML files on the CD using a template and a simple scripting language.

My golden rule for Javascript is that it should not result in inacccessible content for non-Javascript browsers. If it enhances the user experience for those with Javascript then fine, just as long as it doesn’t result in a non-functioning site for everyone else.

Simon WillisonSimon Willison
View Author
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form