diff --git a/docs/topics/LIVEVIEW-OPTIMIZATIONS.md b/docs/topics/LIVEVIEW-OPTIMIZATIONS.md new file mode 100644 index 0000000000..baa6066f99 --- /dev/null +++ b/docs/topics/LIVEVIEW-OPTIMIZATIONS.md @@ -0,0 +1,34 @@ +# LiveView optimizations + +Following are some tips to optimize LiveView performance. + +## Minimize dynamic parts + +1. Use assigns or components intead of function calls: function calls returns a string to the server and cannot be parsed to check what changed and what not +2. Use CSS state/aria/data selector instead of functions or inline conditionals: + - `````` in this case the server will receive all the css classes that returns with the my_class fn. So instead of using the function and inject dynamic code directly in the template, we can use data/aria/state selector (that will remain the only dynamic part ) and add code on the css file (which is passed only 1time on mount) like: ```button class="btn" disabled={@disabled}>increment``` and on the css file : `.btn {...} .btn[disabled] {...}` or can use tailwind variants such `