luksan47 / mars

Eötvös Collegium's Unified IT System
MIT License
4 stars 16 forks source link

Issue #580: Select inits are loaded multiple times #581

Closed luksan47 closed 2 years ago

luksan47 commented 3 years ago

This might cause slowness on pages with multiple selects, like on the mr and miss page. Instead of including the scripts multiple times, which has a lot of content (the whole user list), we could load it only once.

This commit adds a once attribute to the select component, which would let us load the select init script once per page. Note that this can be used only if we have exactly once type of select on the page, as the other would break, since they won't have the same user list in their init script.

Fixes #580.

kdmnk commented 3 years ago

The js initializer will be applied to all the select elements with the given id. I'm just thinking if we could handle this feature automatically, without explicitly setting the once flag. Maybe we can check if the page has already a script for this id or sth like that. @luksan47 , what do you think?

luksan47 commented 3 years ago

We cannot really do that as this optimization can only be applied when the element lists are the same.

However, now that I think about it, I'm not even sure that my solution is working. For some reasons I thought that the select is initializing all selects, and not only the one with the id. If we are initializing only one ID, we cannot use the once directive. We would have to rewrite the JS code as well, replacing #<id> with .select.

luksan47 commented 2 years ago

Please see https://github.com/luksan47/mars#important-notice