Snippet or HTML: which is the best choice for your Shopify theme?

A subscriber Jeremy asked:

I was basically trying to figure out why I’d use the "snippet" thing inside of Shopify instead of just a regular html snippet.

Is there any benefit to creating a Shopify snippet instead of just using that directly?

A snippet is just a piece of HTML, CSS, JavaScript, or Liquid in your Shopify theme that is stored in the snippets directory.

Some apps like JSON-LD for SEO add a snippet which is then added to your theme’s layout.

Other apps like Dripify add their code to the theme’s layout directly.

Jeremy’s asking which way is better.

In my mind they don’t matter that much but if I had to choose, I’d say snippets are better.

Both of them will end up working the same, with your store’s pages getting created by Shopify and sent to your visitors.

Snippets though are easier to manage, both by apps and Shopify designers.

In JSON-LD for SEO for example, the snippet I use adds dozens of structured data items. Many of them have some complex logic around what is shown when.

With a snippet, I can manage all of that in the app and then just automatically update the snippet for your store.

If I used regular chunk of HTML that I added to your theme, I’d need to be extra careful about updating it. This is what Dripify has to do.

In fact, I’m considering switching Dripify to use a snippet too. Drip hasn’t changed their code in all the years I’ve used them but I have been considering adding some features to Dripify that would require updating that code.

I’d say use snippets in your theme. They’re easier to maintain and upgrade.

Do you think you’re site could use some SEO help? Take a look at JSON-LD for SEO (and if you install, you can see the beaufifully complex snippet it comes with).

Eric Davis