Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify HTML before caching #221

Open
kunstlabdev opened this issue Apr 9, 2020 · 3 comments
Open

Minify HTML before caching #221

kunstlabdev opened this issue Apr 9, 2020 · 3 comments

Comments

@kunstlabdev
Copy link

Is it possible to hook up a minifier before caching the template?

I was looking at gluing Selmer and this: https://github.com/yogthos/asset-minifier (more specifically this) but it seems that I would have to run the minifcation on top of Selmer's already cached content?

The thing I am trying to avoid is having to cache twice, or having to run minifcation on requests themselves.

Or should I manually minify the template itself after each edit?

(did I say minify enough times?)

@yogthos
Copy link
Owner

yogthos commented Apr 9, 2020

There isn't any support for minifying the tempates in Selmer itself, but I would be open to adding the option to provide a custom preprocessor function when the templates are read. At the moment you'd have to manage minification manually.

One pattern I tend to use is to have separate resource paths for dev and prod builds. That way you could keep expanded templates at dev time, and have a build hook that minifies them and writes them to the prod resource path at build time.

@kunstlabdev
Copy link
Author

kunstlabdev commented Apr 10, 2020

Thanks for your reply.

After testing a few options I realized that what might work for my use-case won't work for others who want to minify.

As I am using very minimal templating tools, minification as a pre-processing step works well. But if Selmer is used to generate a lot of diverse HTML, then minifcation as a post-processing step would probably be desired.

At the moment I will be manually minifying my templates after each change. Maybe this issue should stay open with a feature tag? Otherwise feel free to close.

@yogthos
Copy link
Owner

yogthos commented Apr 10, 2020

I don't think it would be possible to do minification on the memoized structure as it's tokenized at that point, and doing minification after the output HTML string is generated would create a performance hit. So, performance would be a concern there. That said, you could already do that now with the HTML string generated by the render-file function.

I'm happy to leave an issue as an enhancement though. I can definitely see value in providing pre/post processing hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants