Importing page level javascript libraries into a site level library

How to push local paths to javascript var in ? There would be one init.js for the site, and page level js for obscure libraries, like mathjax, or whatever.

Loading data in both config and at the page level

src = ""

#front matter toml
src = ""

{{with .Params.jsLocal}}{{.src}}{{end}} on a list page should read only, while on any single page adding it should read both scripts.

In the paths are loaded to a variable

<script type="text/javascript">
var script_arr = script_arr || [
{{if .Site.Params.jsLocal}}
{{- range .Site.Params.jsLocal -}}
{{ .src | absURL | safeJS}}
{{- end -}}

In, during onload after scripts loaded the following function pushes page level libraries into

The point is to put the call to in locally stored some.other.library.js to avoid editing messing with

function init(){
$.getMultiScripts = function(arr, path) {
    var _arr = $.map(arr, function(scr) {
        return $.getScript( (path||"") + scr );

    _arr.push($.Deferred(function( deferred ){
        $( deferred.resolve );

    return $.when.apply($, _arr);

$.getMultiScripts(script_arr).done(function() {
    // params.jsLocal loaded here

};//end init

This code comes from here:

include multijs

If you know if the approach is outdated and pointless, that’s great. I’d just drop the page level js into the page bundle, but then the html trigger needs to be added anyway to the main init anyway, and pushing them this way means order can be maintained at page level frontmatter.

Anyway, besides the error in the main.js file, appending data to the site level object from the page frontmatter doesn’t go, so var in doesn’t come through.

Any tips on loading in order page level js into site level js script? Would this be better achieved with headless and page level bundles?