Learn

Hooks

Hooks are ways for add-ons and other code to hook into system events as they happen. There are only a couple of hooks for the front-end at this time, but you now have complete control over them.

A Balancing Act

Plain and simple: triggering a hook is a performance hit. Measuring on our local set-ups, it’s not a huge hit — somewhere around 0.006 seconds per hook — but it’s a hit nonetheless. People have asked us to add in more hooks, but just having them there is a detriment to most for the benefit of few.

That said, add-ons that use hooks are probably doing something important and worthwhile, enough that you’d gladly give up 0.006 second each page load to have that added functionality. For v1.7, we’ve found a way to let you balance the performance-versus-usefulness on your own with each installation.

Starting with v1.7, the _config directory now comes with a hooks.yaml. Right now, it looks like this:

_enable_hooks:
  _render:
    before: false

  _routes:
    before: false

There are only two hooks on the front-end at this time, and by default, both are turned off. When you want to use an add-on that requires a front-end hook, you can turn them on here. The structure in this file lets us logically group similar hooks together so that later on, when there are more, they’ll be easy to deal with.

Because these hooks are disabled by default, add-ons will need to add instructions to turn on hooks as needed.

Back-End Hooks

All back-end hooks are on and not configurable. We enabled turning on and off hooks on the front-end so that you can squeeze as much performance as possible out of your front-end files, but the control panel — while slower than the front-end — is more controlled, is doing much more work behind the scenes, and we feel that it doesn’t need to squeeze performance as much.

This article was last updated on September 13th, 2016. Find an error? Please let us know!