title: Loading JavaScript files selectively in Django
body: <p>I have <code>Post</code> model for a blog app in Django. It has a field named <code>body</code>. In posts, I may use Latex so I need to use <code>MathJax.js</code>. In some posts, I add code snippet, so I use <code>highlight.js</code>. In some I use both, in some I use none of them. </p>
  
  <p>I want to load the relevant javascript depending on the <code>body</code> field of the <code>Post</code> model (similar to <a href="https://stackoverflow.com/q/16691588/2275286">THIS</a>). How can I make the relevant .js file(s) to load automatically? </p>
  
  <p>I know that I can add an indicator field like <code>hasLatex</code> (<code>True</code>, <code>False</code>) or <code>hasCode</code> (<code>True</code>, <code>False</code>). But I'm lazy, I want <code>Post.body</code> to be automatically scanned and only relevant js files loaded. </p>