HEIGE-PCloud / DoIt

A clean, elegant and advanced blog theme for Hugo.
https://hugodoit.pages.dev
MIT License
800 stars 198 forks source link

[FEATURE] load lightgallery js on demand #1382

Open wu0407 opened 2 weeks ago

wu0407 commented 2 weeks ago

Describe the feature you want 描述你的功能需求

The lightgallery resource is large, so need to optimize loading speed. It is very difficult to determine whether there is an image in the summary of the homepage on the render. But It is easy to determine whether there is an image on the article page. There are many pits about Scracth Store and render cache on the Hugo server. https://discourse.gohugo.io/t/strange-behavior-with-scratch-variable/52288/11?u=xiao_qing

So The best method is to load it on demand from the front end.

Useful reference 有价值的参考

No response

HEIGE-PCloud commented 1 week ago

I think the easiest fix is to just mark these scripts as deferred

https://github.com/HEIGE-PCloud/DoIt/blob/e68974c47e4bcf086c6a0dbff153352e71fcfd16/layouts/partials/assets.html#L56-L60