Add custom .js files to Ghost locally

Hi,

Is there any way to add your own .js file to use? I want to add Prism.js and host the .js file locally. However the amount of JavaScript is to much to fit in the code injection section. Where should I add my custom .js to be able to load it on my Ghost blog?

Why do you need to add this locally? Is there any special reason?
You should just use the CDN as everyone does and just put the necessary script in the code injection. If you need a tutorial, here’s a couple:

https://ghost.org/tutorials/code-syntax-highlighting/#customising-prism-js-themes

https://ghostportal.co/line-highlight/

Hope it helps.

I want to control the whole delivery and also avoid CDNs that is reported by Decentraleyes and Privacy Badger. I know that you can use CDNs, that’s how I’m currently embedding the scripts.

Also I used Prism’s custom configurator which outputs a custom .js-file, that exact configuration isn’t on any CDN.

Hey @Seb :wave:

The best method to locally host assets like this are through your theme. Code injection is generally used for minor modifications, and adding a large script like prism is kind-of out of its scope

2 Likes

You’re the man! Tried adding it to /assets/js and it worked flawlessly.

You beat me to it. Exactly that :slight_smile:

I understand now. @vikaspotluri123 told you the other option around.