Svelte – The magical disappearing UI framework
svelte.technology
svelte.technology
The file size problem is about unused code, right? If we tree-shook the runtime and shipped the minimal version that our app needs, wouldn't that be even better for most apps than inlining the framework? I'd expect that, the moment you use a feature even twice, the runtime approach yields a smaller bundle.
Or is Svelte accepting a file size penalty to avoid the performance overhead of function calls? If so, it'd be nice to see that tradeoff discussed more explicitly: in every app, there are probably features worth inlining and features worth keeping as function calls.
Really, it sounds like Svelte is trying to solve a very general compilers problem with a very specific sledgehammer solution. Sure, tree-shaking and thoughtful inlining are difficult to do well, especially in Javascript, so this makes sense as a first draft for certain use cases. I just wish it were touted as a first draft, rather than a new beautiful finished paradigm.
I'd like to see some performance metrics from Svelte compared to page loads with other frameworks to see where the savings are.
I've heard this sentiment a lot. The reality is that UI libraries are inherently difficult to tree-shake. You can't run a library that can be used to produce an infinite range of outcomes and expect a tool like Rollup to whittle it down to just the bits you need (source: I'm the creator of Rollup).
Code is reused. While the compiler will output 'standalone' modules by default, it can also generate modules that share code between components — the zero-runtime part is about generating abstraction-free DOM manipulation code rather than having a complex virtual DOM reconciliation or data-binding process.
> rather than a new beautiful finished paradigm
Nowhere does it claim to be finished. If anything, it's the start of a new approach to building UIs.
Is that correct? If so, it's a very cool idea! (I'd been tossing this idea around for a few months last year, but had trouble designing a non-awful API xP)
I wish there were a way to make the messaging around this idea clearer. I know that audiences are different, and this wouldn't work for everyone. But if the introductory blog post had illustrated the transformation from component tree to data graph, I would've immediately understood the performance implications and how this represents a huge paradigm shift in application compilation.
Instead, though, I thought the pitch was "ew, separate runtime library? let's inline it and then it'll be smaller", which seemed misguided. I had to reverse-engineer Svelte's motivation from your comment—and even now I'm still not sure I got it right. (Maybe this entire comment is wrong? Could be wrong. No idea :/)
Are y'all planning a blog post about how Svelte works under the hood? That would go a long way toward clarifying the pitch, I think.
Both are solid ideas. (As the creator of Ractive I'm biased towards data-binding, but React's success speaks for itself.) But either way, the library has to do a lot of work to essentially just translate state changes into `element.setAttribute('foo', 'whatever')` and so on. Svelte was born out of a realisation that if you can understand the shape of your component graph at build time, you can eliminate those runtime abstractions — and with it, both the bytes and the computational cost associated with them.
> Are y'all planning a blog post about how Svelte works under the hood?
Yes, we have a lot of blog posts we need to write! Hopefully soon.
Direct DOM updates are slow (rerender), diffing and smart patching much faster. There must be a reason for virtual doms becoming so popular, even for frameworks that don't have a 'functional' approach like React.
Re-rendering your entire app (i.e. creating all the nodes from scratch with innerHTML or document.createElement) is too slow for a lot of apps, and is a bad idea for lots of other reasons (losing state in form elements, etc). Virtual DOM just gives you a way to write your app as though you were re-rendering it from scratch, while still being fast enough that you can get away with it.
Svelte is significantly faster than React according to https://github.com/krausest/js-framework-benchmark, because it's taking a more direct approach to the same goal — updating existing elements or only creating/destroying them as necessary. It's also faster than Ember, Angular, Vue, etc. It's not yet quite as fast as Inferno, but it uses less memory.
Inferno-1.1.0 have an error at runtime, could not test JS Framework right now. Sveltejs works.
Svelte – A UI framework that compiles into tiny standalone JavaScript modules (svelte.technology)
533 points by bpierre 38 days ago | 228 comments
[1] https://news.ycombinator.com/item?id=13069841I have a couple questions just off the homepage that I didn't quite really get answered:
- Can I use webpack? Can I add this into my current webpack flow?
- Can I use TypeScript?
- How does this compare to preact? Note that their homepage has a lot more info than this one: https://preactjs.com/
- Unsure
- Preact is essentially a lightweight implementation of React. As such, it requires a runtime, albeit an incredibly small one, to dynamically render HTML from JSX (Edit: Well, compiled JSX. Essentially hyperscript function calls.).
Svelte components compile at buildtime to pure es5, so you can just run it directly on the client without a runtime.
There are benefits and drawbacks to each method, but that's the gist of their main differences.
If I use Svelte to make my site, is the expectation that the data is being loaded in the cacheable HTTP call or is it a SPA?
If you visit the REPL you can click on the 'output' button to see some sample output code: https://svelte.technology/repl
> Can I use webpack?
Yep, there's a webpack loader: https://github.com/sveltejs/svelte-loader
> Can I use TypeScript?
Integration with things like TypeScript is on the nice-to-have list — we have an issue here: https://github.com/sveltejs/svelte/issues/58
> How does this compare to preact?
Last time I checked, Svelte was faster. Need to get some automated benchmarks up and running, and compare sizes (and parse & startup time) for equivalent non-trivial apps.
Then why does Svelte wants to be yet another framework? Do a real good one to the world and be something that you can plug into Gulp or a Makefile...
> Do a real good one to the world and be something that you can plug into Gulp or a Makefile...
You can easily use Svelte in Gulp tasks or Makefiles. Maybe do a tiny amount of research before criticizing something. God the HN crowd is tedious sometimes
So, the idea is to be kind of like Web components? Even after reading the comments in this thread and the website it is hard for me to grasp where Svelte's place is. Is it for people who need the performance without giving up the work flows of the regular frameworks they are so used to? If it is for encapsulation I would say webcomponents is the better choice here? Although you could argue Web components isn't ready yet either for the big masses.
Also, with Svelte you can do server-side rendering, which is a bit of an oxymoron with web components.
B) OK. Though subjective.
C) Active support for this is a nice thing to have.
Guess it ain't enough for me to use hut I see its use for others. Still, YAJF as far as I'm concerned.
Well, you might be waiting a while! Web components are actually four separate specs. While templates are widely supported, the future for custom elements, shadow DOM and HTML imports is less clear (well it's very clear for HTML imports — it ain't gonna happen). Edge is 'considering' whether to implement shadow DOM and custom elements, Firefox says they're 'in development' but from the outside it looks like that development has stalled.
Even if web components had major advantages that outweighed their disadvantages, personally I'd be very hesitant to use them until browser vendors make their intent to support them much clearer.
This doesn't seem like a great strategy for long-term success. It got to the point with me that I didn't want to invest any more time in Javascript technologies, simply because their lifespans seemed to be quite short, compared to other options. In the Javascript community, framework feel disposable. I don't mind learning, but there has to be time for implementation and mastery, and there has to be some level of long-term career payoff for the time invested in learning. For example, I can still get any number of Rails jobs after 11 or 12 years of using the framework. Can the same be said of the original Express.js? I know it isn't a comprehensive, scientific study, but a quick search on local job boards in my area turns up 15 Rails jobs, and no Express.js jobs. No Hapi.js jobs. No Metor jobs. No Mithril.js jobs. No Derby jobs.
I don't mean to take away from the successes the Javascript community has had over the years. Javascript is certainly in a better state than it was a decade ago. However, having so many libraries and frameworks come and go so quickly isn't a good thing, in my opinion. I think the community could benefit a lot by embracing more cohesion and focus, but that's just my opinion, based on my experience with other languages and communities.
Vue.js is probably here for a while, though a little uncertain, there's definitely some desire there. I'm not sure about Polymer and web-components, I think there will definitely be more web-component packages to work from in the future, but for now, just kind of holding off myself.
I'm pretty actively following the JS world, and tbh in 2012 I felt so in over my head as npm was growing... It's gotten easier. In general, your best bet is to stay a little behind the bleeding edge and look at what the heavy hitters are investing time/money in, and beyond that what you like.
I'm pretty heavy in the React camp (including Preact, Inferno, etc)... Most of the look-alikes are compatible enough to work, or have a similar enough workflow. I happen to like the component structure, and am a fan of Redux as well. Others have hunkered down for Angular2+.
So while I can pick a framework like the ones you mentioned and stick with it convincing team mates or colleagues to do the same becomes difficult.
To be fair, I have had colleagues want to switch to some new framework for $reasons, but I guess I have enough sway (and we're time-constrained enough) to not do just that.
I'm trying to bring "nifty" back. What do you think? No?
@tracker1 - You're kind of speaking to my point. Most of the frameworks you mention basically do the exact same thing, or subsets thereof. Does the Javascript community really have to be this fragmented to be successful? Other communities aren't. Maybe it does. I don't know, which is why I wanted to discuss it.
I am not sure why it is taking so long for things to gel in JS/DOM land though. My best guess is that it is because JS is essentially the only programming language that can be used in the browser. Programmers coming from a myriad of different language backgrounds have to use it and they use it in ways that make the most sense to them. If you're a python dev you still have to use JS on the front-end. If you're a PHP dev still gotta use JS. etc. etc. It is all things to all people and thats not easy.
The older libraries (that caught on) are still perfectly fine to use. There's no reason you can't still be running an Express.js app with Backbone.js + RequireJS (for modules) in the front-end.
We have a Backbone.js + RequireJS app at work and it's totally fine, well structured OOP, and arguably a great codebase in comparison to some Angular 1 architecture horror-stories I've heard about.
Of course it takes strong, level-headed devs to say "no we're not rewriting it in Angular".
In terms of jobs, being able to search for 'framework + jobs' is kind of insane anyway. 'language + jobs' makes more sense, a dev should be able to pickup any framework pretty quickly.
Not everyone in the Ruby community was that happy that Rails become so defining, you could argue that it was an anomaly to have a language so dominated by 1 framework.
That said I do prefer Rails/Django over any backend Node framework to-date, at least when it comes to the DB/ORMs/migrations story (which then lead to mature CMSs too), so I don't love that no Node backend framework grew comparable mindshare there.
As for migrations, I'm a little more old-school, I prefer versioned scripts/rollbacks that are hand-crafted for SQL, or for very large document/column databases on-read/save upgrades.
Backbone works... though I was in the browserify camp over requirejs/amd, mainly because I wanted the same syntax/modules without umd overhead... moving towards Webpack was a sinch.
Keeping what works is often a good idea, I wouldn't suggest even trying to rewrite everything in one pass for most things. To GP, almost everything revolves around Express server-side, there are other options, but that's still the bulk of the mindshare in my experience, even if I do like the way Koa works slightly better.
For that matter, jQuery really rules the world still, even if the mindshare has declines, and likely wouldn't reach for it for new projects.
Consider this: I can still use Delphi to make Windows apps too, but where am I going to find a job? Being able to use an old tool isn't my point. My point is that while you may still be using Express.js where you work, there are many other Javascript companies who aren't using it anymore. They've moved on. Even the Express.js developers have moved on to something else (Koa), so by mastering Express.js, you sort of paint yourself into a corner in your career. You most likely won't show up on recruiting radars, since you don't have the latest JS buzzwords on your résumé, and if you try to go get another Express.js job on your own, you'll have a more difficult time of it. The high turnover rate of JS frameworks works to your detriment, I would think, because it is more difficult to keep up with all the moving targets.
If JS programmers don't see their framework-du-jour culture as a problem, then by all means, keep doing it. I just think you'd be better off, and attract more developers, if you congregated around the best framework or two out there, and worked to make them the best they can be, instead of re-inventing the wheel every other day. I'm simply bringing it up as a point to consider for making the JS community more stable and cohesive, and worthy of personal investment. I know this fly-by-night aspect of the Javascript community is one of the reasons I don't bother with server-side JS. I know a lot of other developers in my area who feel the same way.
Just something to consider...
> The high turnover rate of JS frameworks ...
> this fly-by-night aspect of the Javascript community ..
All those things are your interpretation. But please hesitate when generalising like that and stating your opinions as fact, and think about what is actually going on here.
The JS community is larger than any other, and very good at promoting its stuff (great landing pages/demos/docs, lots of conferences, podcasts and bloggers).
This can give the appearance we're switching tools all the time, but actually in the few jobs I've worked, that simply wasn't the case.
And on Express.js specificially, that is not a great example of your point at all. Express is still the defacto winner by my understanding. I wouldn't pick Koa, because it's a niche thing to use a framework built around generators. The fact that original Express people went on to work on it is irrelevant (though I see it could be a confusing signal to the community).
And again I want to reiterate on the jobs thing, that (in my opinion, granted) you are not painting yourself into a corner picking any one framework because recruiters shouldn't be looking for any specific framework, and if you find in your interactions with them that they are, then it's up to you to set them straight.
Time to mount the JET emitters and blast out that code.
I spent a few days testing and it was an eye opener, compare to the numbers of >100 outstanding issues filed in React, Angular, etc which may probably never fix it for some reason and complexity.
Semi-similarly, there's three reasons why React (and other libs) have that many issues: they've been around for a while, they're very popular, and the wide variety of usages has led to a number of edge cases being found. Svelte, being new, hasn't run into any of those things yet. Things like style of development can also affect things - some communities might file more issues than others.
I've found React proper does a pretty decent job of running everywhere I've needed, though I have used preact for smaller extensions, and bits that are adding to an existing app, where I want to add new React-style code, to keep the size down.
I talked to a couple of programmers about the project, and they laughed at me because of the name, dismissing the project and not even wanting to hear about it.
Everyone keeps saying that the name is not important, citing examples like Yahoo, Google etc., but it is.
I was reading about how execs didn't want to replace Android with Cyogenmod, and I bet part of the reason is the name. It's hard to pronounce, it contains "mod" in it, and it sounds like a tool for hackers instead of a reputable operating system that corporate would be ok having on all their phones.
"Svelte" sounds like a name for a dish washer brand.
But yes, it seems that a lot of people, at least here in the US, aren't familiar with the word.
It doesn't matter though. I build tools for my job because the existing ones don't meet my needs, and then I share them because there's no good reason not to. I couldn't care less whether or not people use them as long as the ideas get out there. So if someone decides not to use Svelte because they don't like the name, all I do is shrug.
It doesn't seem like you care (I guess rightfully), just a note.
Clearly a sign that you should avoid listening to said programmers on any important matter from now on, because they are 16-year olds inside (not to mention they haven't even bothered to open a dictionary in their lives).
Reminds me of people that laughed at iPad's name (because of the maxi-pad connotations).
https://news.ycombinator.com/item?id=13349986
http://arstechnica.com/gadgets/2017/01/dells-latest-xps-13-d...
So your friend programmers may take note that it is a valid word.