Comments (9)
Was about to suggest the similar optimization. Plucking methods like document.createElement
into the variables at the top of the module (like const __createElement = document.createElement.bind(document)
) will help the minifier when the components have many nodes.
from svelte.
Yup. I did a little test locally yesterday, and found about a 20% savings by doing this on a relatively small project.
from svelte.
We should definitely do this. As a starting point, helpers like createElement
and detachElement
would reduce the size a bit (gzip notwithstanding) and could be externalised if necessary. I hadn't thought of custom factories though, that's an interesting idea.
from svelte.
cloneNode could be helpful here, too.
from svelte.
BTW does it make sense to have elementWithClass
actually compatible with React.createElement
which is (name, attributes, children)
?
Who knows if it will provide some positive side-effect like JSX compatibility?
from svelte.
@emirotin you want to avoid polymorphic functions like that, that's why Inferno avoids them in core – they result in functions that can't be properly optimised.
from svelte.
Interesting @trueadm thanks for the insight.
from svelte.
Helpers have been in Svelte for a while, is this issue open for other helpers? Like the suggested elementWithClass
and potentially similar ones like elementWithId
?
from svelte.
Probably slightly trickier to do elementWithClass
in Svelte's current form, because creating nodes and adding attributes happens in two separate places (so that hydration can work). So maybe we should close this and revisit it if we ever need to eke out a few extra microseconds 😀
from svelte.
Related Issues (20)
- Unused CSS detection considers snippets to be external for combinator selectors HOT 2
- Add 'clear' and 'size' methods to the Map type in 'svelte/reactivity'. HOT 3
- Svelte 5: capture events do not work. HOT 1
- Binding value in object will trigger twice updating in input[type="range"] HOT 1
- Hydration logs error and breaks HMR for web components that error on getters
- Svelte 5: [reopen] Optional parameters in snippets don't work HOT 1
- Svelte generates `innerHTML` assignments breaking CSP "require-trusted-types-for 'script'" in production code
- Nested updates are not picked up by each blocks HOT 10
- reactive assignments not triggering a rerender HOT 3
- trying to render a derived value throws HOT 6
- Derived subscribe HOT 1
- Svelte 5: State mutations in $effect breaks $derived HOT 1
- Using adoptedStyleSheets in custom elements HOT 1
- Won't build with Ollama
- Invalid types generated (likely dts-buddy bug)
- 'visible' and 'viewportPosition' values available as props when creating a custom transition. HOT 1
- Safari autofill doesn't change bound value on number input HOT 2
- Preserve unused CSS when nested within used rules HOT 1
- ParseError when using camelCase names in CSS container queries HOT 2
- $derived.by rune does not fully replace $:{....} Cannot change propValue based on another reactive value HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.