Javascript per page


Is there a way to add Javascript and css files to the header on a per page bases? I am using the Academic Theme which has a provision for adding custom JavaScript and CSS site wide, but I would like to only load the javascript and css on a per page bases. Academic documentation:

Yes. However you designate a page, load a conditional that checks for that condition and load what you need. One suggestion is front matter.

Doing so requires understanding which template you are overriding to add your conditional, and producing the conditional statement to check. Please refer to many docs. :slight_smile:

My solution, in an environment where I am the only one editing, was to create a frontmatter param with the <script> tags I need.

date: 2019-03-07T21:39:59+01:00
description: ""
draft: false
- src: images/eQdX_nIQ.jpg
  name: "header"
subtitle: '#TwitterchatPT #9'
title: "title goes here"
  - '<script async src="" charset="utf-8"></script> '

and then, in baseof.html:

		{{- with .Params.scripts -}}
			{{- range . -}}
				{{- . | safeHTML -}}
			{{- end -}}
		{{- end -}}