How to organize code entered from the head tag?

I am adding a variety of code to my discourse forum that generally is meant to run when various pages load. So far, I’ve just been adding it to the head tag in my customization dashboard, and it works fine.

However, now the code is getting fairly long and complex, so I’ll have to organize it into sections. I assume the way to do that is to move it to a remote theme.

Assuming that’s the case, here’s the question: bc of the code’s complexity, I want to separate the code that currently sits in the head tag into different files. What’s the best way to do that in a remote theme?

Different code is meant to run on different pages. So one block of code is supposed to run on the topic show page, one on the category show page, one on the groups index, etc.

Can I create different head.html files that each are linked to these different pages in my theme’s codebase?

Or just some other way of organizing this head tag code into different files to make it manageable?

I’ve reviewed the developer’s guide but did not find info on this issue.

1 Like

Did you take a look at Splitting up theme Javascript into multiple files?


The Splitting method described there works well. Thanks for the info. I’ve provided detail on how I implement it here.