Skip to content

Commit

Permalink
Enable caching of compiled Jinja templates
Browse files Browse the repository at this point in the history
This should reduce startup times a bit.
  • Loading branch information
oprypin committed Apr 30, 2023
1 parent ea1c6c4 commit a80a481
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mkdocs/theme.py
Expand Up @@ -114,8 +114,16 @@ def get_env(self) -> jinja2.Environment:
"""Return a Jinja environment for the theme."""

loader = jinja2.FileSystemLoader(self.dirs)
# No autoreload because editing a template in the middle of a build is not useful.
env = jinja2.Environment(loader=loader, auto_reload=False)
try:
bytecode_cache = jinja2.FileSystemBytecodeCache()
except Exception:
bytecode_cache = None
env = jinja2.Environment(
loader=loader,
# No autoreload because editing a template in the middle of a build is not useful.
auto_reload=False,
bytecode_cache=bytecode_cache,
)
env.filters['url'] = filters.url_filter
localization.install_translations(env, self._vars['locale'], self.dirs)
return env

0 comments on commit a80a481

Please sign in to comment.