Add custom JavaScript to a Jekyll page

I’m reading the Jekyll documentation about how I go to add my own JavaScript code to the website or to a specific page. I read in the documentation where to add the coffee files but I don’t write coffee I want vanilla JavaScript. Does anyone know how I can do this?

I believe you should be able to simply put Javascript files to _assets folder and then reference those as regular assets in your layouts or anywhere else.

Also, I would recommend to take a look at jekyll-assets documentation here: https://github.com/jekyll/jekyll-assets/blob/master/README.md. There you can find some good examples how to reference Javascript assets.

Hope that helps!

You can put your JavaScript files anywhere you like. You just need to reference them using the correct paths in your _includes and _layouts.

A common practice is to place them in a folder like assets/js which Jekyll will copy and place into _site/assets/js.

If you need or want to concatenate/minify JS then you’ll need a plugin like jekyll-assets as @pabloduo has suggested above. You can also use something like Gulp or Grunt to do that for you independent of Jekyll’s build workflow.

1 Like

Thank you for the explanation @mmistakes. As HTTP2 is out and running I think I’m not going to minify files.

I found that /assets/ as js folder does not work, but /assets/js does.