Embeds versus Snippets in ExpressionEngine

ExpressionEngine is very flexible system with so many different ways to build the same thing. A plethora of extensions make it into an incredibly powerful framework which can do many many things. Even when we are building up templates there are numerous ways to go. With the launch of EE2 after years of delay along came snippets.

Previous to snippets embed templates were the way to go, has things changed?

In short not really. The general consensus we believe anyway, is that snippets are handy and should be used more than they are but are very limiting.

Why on earth would you use snippets over embeds anyway? The answer is performance. Snippets are smaller, more optimised facets that work differently in the parse order. With performance increases comes less features, trade offs, as with just about everything in web design and development.

When snippets came out in ExpressionEngine version 2 they weren't able to be stored as files, since then there has been a number of add ons which allow them to be used exactly as that, such as Libraree, Snippet Sync and SnippetsSync, no not an typo just a very similar sounding addon, well almost identical.

  • If you are using embed variables – Do not use Snippets
  • If you want to cache certain templates – Do not use snippets, although plugins such as Stash could work around this.
  • You need the template to work as to produce a url – Do not use snippets, this is a big one for us, we build many sites where embed templates are used as the url for the parent and child pages.

We are certainly ourselves going to use more snippets in projects, performance can be an issue on some sites. What we highly recommend is trying out snippets and looking at the performance issues for yourself using the output profiler. A saving of 40% in rendering time which can be reality on a template adds up and can really help out on heavily used sites. It certainly isn't the end of the world if you don't use them at all however, but every little helps in building a leaner, meaner and more efficient ExpressionEngine site.