6 ms·
One minor caveat I'd add- JS is slow, but you don't always have to use it. I've had great results using a little JS coupled with hardware accelerated CSS transi
by untog 13y ago
One minor caveat I'd add- JS is slow, but you don't always have to use it. I've had great results using a little JS coupled with hardware accelerated CSS transitions, animations, etc.
Web apps are slower than native, that's undeniable, but they're only really slow when you port bad desktop practises ($("#home").animate() and the like) over to mobile.
- pachydermic 13y agoI'm just learning JS - I've had plenty of experience with more technical scripting languages, but I'm still a JS newbie. Is that a bad practice just because that kind of code is optimized for desktop use or is it just bad practice in general? Also, a broader topic I'm wondering about: JS and HTML seem pretty clumsy. I find it hard to believe that they're really how the majority of web pages run. Is there really no alternative? Or is it just the case that these tools are "good enough" and what really creates problems is bad code(rs)?
- Pxtl 13y agoThe tools are "good enough" but just barely, and very good coders have gone to herculean lengths to make them usable. The thing is that these spectacular achievements are available to all, making it into a decent platform. But naked HTML/CSS/Javascript is a document/hypertext engine perverted into a general-purpose platform. The thing is that the JS libs and practices used for desktop generally aren't mobile-friendly so even though everything works across all the platforms, it's not necessarily usable.
- PavlovsCat 13y agoIs that a bad practice just because that kind of code is optimized for desktop use or is it just bad practice in general? I think the point here is that if you use Javascript to animate, that runs in, well, Javascript, and has to be called constantly. If you set a CSS property to achieve the same animation, the computations for it are done in native code. It still gets drawn the same way, but it's basically throwing away CPU for nothing (unless you do something that can't easily be replicated by CSS of course).
- dclowd9901 13y agoIt's not easy to say whether it's a bad practice or not. I think more than any other platform, how your application is going to be used, and who it's going to be used by are vital points of information that you need to answer before you approach the issue: 1) Are your visual flourishes vital to the quality of your product? 2) How concerned are you with baseline performance? 3) How big is your application? Do you need disparate components to be reusable, or do you need a philosophy or underlying framework to guide development? 4) Is your application going to be used on mobile? The answer to 1 dictates how you should approach things like animating elements. Much of the time, the animation is really just a visual flourish, and can be handled with graceful degredation through CSS. Plus you can learn a few tricks using just CSS that don't trigger unnecessary redraws that might happen using JS. The answer to 2 dictates whether or not you should adopt an existing framework or library vs. rolling your own. Libraries have gotten better about making themselves available piecemeal, but if you know how to write quick code, you'll often find almost everything is not quite what you absolutely need. See Canvas game dev. Question 3 will determine what sort of framework you'll want. Something that is extendable and object-oriented, vs. something that has more self-contained reusable components. The drawback of the former is that classing in JS brings in a considerable performance hit, whereas reusable components make for much more unmaintainable code. Question 4 will play a roll in all the aforementioned questions, namely where matters of performance and DOM redraws are concerned, as that's where mobile tends to fall flat when it comes to web apps.
- Me1000 13y agoHow often does a native developer "trick" their framework to trigger an implementation detail to get performance gains? That's really I can think about when I hear web developers talk about "hardware accelerated CSS".
- talmand 13y agoHow is using a CSS feature "tricking" the framework? If it's a trick then native developers are using the same trick when they use the device's video hardware, for the same reasons, instead of relying on the software renderer.
- Me1000 13y agoIt's a trick because you set a 3D property on a style and _sometimes_ the the browser will use the GPU instead. We've actually seen browsers (Safari on iOS) turn off this implementation detail in same cases where it used to be enabled. Your video example is interesting, but for a Cocoa developer they'd just create a video player object and give it a file to play. Cocoa doesn't make any guarantee it will be hardware accelerated (neither does the HTML5 spec for that matter), but you can be assured that if Cocoa says it can play a video it will be able to play it properly; you, as the person using the framework, never have to worry about any implementation details.
- talmand 13y agoWhat 3D property are you speaking of? Maybe you're meaning that using a 2 dimensional transition corresponds to a 3D property that causes the hardware to kick in then I suppose you make sense. But the thing is, I fail to see how that's a "trick" when it's an implemented feature of CSS. Also, if a browser vendor turns off the feature then that's a problem of the vendor and not CSS. Again, you are labeling a feature as a "trick" to paint a negative picture of web apps. Believe me, there's plenty of room for improvement in the area of web apps but your example isn't holding up. I wasn't speaking of playing videos to the screen. I was referring to the hardware in the device that renders pixels to the display, specifically the hardware accelerated part. That's the PC gamer side of me referring to that hardware as video cards or video hardware. But to combine your Safari and Cocoa examples. If Safari says that it doesn't have hardware accelerated CSS features enabled then you know that the feature doesn't work as nicely as you would want, but the transition will still happen. If Safari says that it is enabled... nah, never mind. Regardless of hardware support or not; you, as the person using CSS, never have to worry about any implementation details. In fact, since CSS isn't a framework, it's far more efficient to use CSS over a Javascript framework anyway, regardless of hardware support.
- doctorpangloss 13y ago> In English: the philosophy of JavaScript (to the extent that it has any philosophy) is that you should not be able to observe what is going on in system memory, full stop. Mobile web apps are slow because they're secure, precisely for the reason that they cannot examine or manipulate underlying system memory. Manipulating memory is fundamentally a bad desktop practice incompatible with the way that JavaScript—i.e., untrusted software—is distributed. Most browser vulnerabilities come from manipulating the browser's underlying C++ objects, causing leaks & buffer overflows. E.g., the WebRTC bug in Chrome which provides a full sandbox jailbreak, or the TIFF/PDF exploit in MobileSafari from iOS 3 (jailbreak.me).
- weland 13y ago> Mobile web apps are slow because they're secure, precisely for the reason that they cannot examine or manipulate underlying system memory. By that logic, they'd better start writing OpenSSH in JavaScript, unless they want to compromise every server in the world. Oh no! Secure doesn't imply slow. Not even sandboxed implies slow. Mobile web apps are slow because their runtime has more layers of functionality and is more complex -- therefore, it requires more processing than a native application. > Manipulating memory is fundamentally a bad desktop practice incompatible with the way that JavaScript—i.e., untrusted software—is distributed. This simply isn't true. Native Android applications also can't manipulate memory; how are web applications more secure than those? And if they aren't, why are they slower?
- ANTSANTS 13y ago>Mobile web apps are slow because they're secure, precisely for the reason that they cannot examine or manipulate underlying system memory. I believe the idea he was getting at was "you need to be able to tell how much memory is available to your (web) application, how much of that memory you've already used, and you need to be able to accurately predict how much memory will be allocated in the course of performing an action, in order to achieve acceptable performance on mobile," not "you need to be able to directly bang the address space." You can certainly have those features in a safe language.
- 13y ago