Use simple variables to define your master files, presets and manual insertion. Select your assets dynamically via page front matter and config.yml
View Gem on rubygems.org
View Gem on github.com
Jekyll_Dynamic_Assets is a powerful Jekyll plugin for dynamic, flexible, and DRY asset management. It lets you define, group, and inject CSS, JS, and other head assets using presets, per-page config, and custom formatting.
{% assets %}
for easy asset injection in templates and includesAdd this to your Jekyll site’s Gemfile
:
source 'https://rubygems.org'
gem "jekyll"
group :jekyll_plugins do
gem "jekyll_dynamic_assets"
# other gems
end
Then add the following to your Jekyll site’s config.yml
:
plugins:
- jekyll_dynamic_assets
Finally, in your terminal run:
bundle install
config.yml
assets:
master:
- main.css
- main.js
source:
base: /assets
github: https://github.com/assets/
css: /css
js: /js
absolute: true # Use absolute URLs (uses `url` and `baseurl` from config)
presets:
blog: [blog.css, blog.js]
project: [project.css, project.js, code-highlight.css, slideshow.js, myApp.js]
formats:
js: <script defer src='%s'></script>
xyz: <custom> %s </custom>
screen-css: <link rel="stylesheet" href="%s" media="screen">
If all your assets are in the same folder, you can simply do:
assets:
source: /asset_folder
Path rules: Always use a leading slash, never a trailing slash.
In your page or post front matter:
assets:
files: # See Asset Definition Syntax below
- manual.css
- onscreen.css::screen-css
- no_script.css:::<noscript><link rel="stylesheet" href="%s"></noscript>
- github<<master.css
- /css/new<<<new-main.css
presets:
- blog
- project
Use the Liquid tag where you want the assets to appear (typically in your <head>
):
<head>
<!-- other tags like meta etc. -->
{% assets %}
</head>
This will output the appropriate HTML tags for all configured assets. The tag should generally be used inside your <head>
tag but can be used anywhere else.
You can use the following syntax anywhere (config or front matter):
Source<<Asset::Format
<<
uses Source
as a variable from config; <<<
uses Source
as a literal.::
uses Format
as a variable from config; :::
uses Format
as a literal.base + Source
.NOTE:
base
without sub-directories.Bug reports and pull requests are welcome on GitHub at MUmarShahbaz/jekyll_dynamic_assets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the JekyllDynamicAssets project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
The Archives of M. Umar Shahbaz
© 2025 MUS. All rights reserved.