-
- 24,544 Posts
If you don't need it to be dynamic, the best event would be OnDocFormSave or OnBeforeDocFormSave, so the changes will be saved to the database, then cached on the first visit. The slowdown will only happen once when the page is saved in the Manager, instead of on every single page visit.
Changing to another event that's part of the rendering process probably won't save you any time at all. The time it takes for your code to run will be added on every page load regardless of which event you attach the plugin to.
If you need the TOC to be dynamic, you'll be much better off with a snippet in the template rather than a plugin. The snippet's output and the page itself can be cached. Every time you add a new resource, the cache will be cleared when you save it, so the output should always be up to date and your code will only run once when a new resource is created.
-
- 9 Posts
Hi BobRay,
thank you for your extended answer. I created 3 plugins:
1) Markdown (I'm writing in Markdown) and generate HTML
2) Generate Table of Content from HTML (Because its more flexible than from markdown e.g. when html content is used)
3) Generate a second navigation for anchors from HTML
Because of Markdown, I'm not sure if a snippet could work and if docsave can be used. I don't want to change the original content.
[ed. note: MoonMaker last edited this post 9 years, 5 months ago.]
-
- 24,544 Posts
I think what I would do in your case, if you're not satisfied with the page-load speeds, is extend modResource with ClassExtender and store the TOC and HTML in custom fields -- updating them whenever the resource is saved. Then retrieve those fields in a cached snippet so the snippet will only run when the page changes and the cache is cleared.