Squoosh: Make images smaller using best-in-class codecs, right in the browser
squoosh.app
squoosh.app
And the WASM sandbox should be airtight, which means it's much safer to run C code in WASM than directly!
I'm mainly a Python developer, so an accompanying revelation was that projects like wasmer-python then give me the same opportunity in my default environment - call out to best-in-breed C/Rust/etc libraries without the risk and misery of needing to compile and package them as Python extensions. Instead, wait for the JavaScript WASM community to figure out how to use them and take advantage of their work from my Python projects as well.
Java/JVM is a strong compilation target but it is mainly a language and an ecosystem, wasm is building an impressive ecosystem but it is mainly a compilation target designed to be easily embeddable anywhere.
Essentially the only things they have in common is the "run everywhere" slogan.
To actually answer your question with my opinions:
- wasm has a stronger sandbox and will (likely) never have any runtime reflection capability
- wasm is primarily meant to be easily embedded/interpreted
- wasm is extremely small
- it offers no new functionality that isn't already present in javascript (this will eventually become false)
- wasm lives within the sandbox of the browser
- it is standardized together with javascript inside the web platform, not as a separate entity
Java applets had built-in access to the complete filesystem, network, shared memory etc. A java applet could read cookies, credentials etc stored on disk and transmit them elsewhere - this was not "hacking", it was merely "write the code to do it".
By contrast, the WASM standard offers no access to anything - no IO of any kind. The only documented way to do IO is to have the hosting code (eg javascript) pass in a function pointer to perform IO on behalf of the WASM.
You could definitely go looking for a vulnerability in a particular WASM engine which let you escape the sandbox on that engine - and I have real concerns about JIT type-confusion vulnerabilities, and the GPU as an attack vector. However, "find a vulnerability to exploit" and "call an officially-documented method" are very different approaches to performing IO.
This is definitely not true:
https://docs.oracle.com/javase/tutorial/deployment/applet/se...
It says you can only access the local filesystem from "privileged applets" that are explicitly allowed to run outside the sandbox.
Because neither Sun nor browser vendors had interest in doing the work needed to improve sandboxing in Java; browser vendors had no say on Java development and Sun care more about non-applet Java
> How does that improve the sandbox?
The same way rewriting a C program in a memory safe language will decrease null pointer exceptions. wasm is closer to brainfuck in terms of functionality than Java applet.
> If the sandbox is the problem, why not work on that?
historically because nobody wanted of could, technologically it is what happened
> How do you know how strong the WASM sandbox is, really?
This only time will tell, but there are many reasons to be optimistic: wasm offers no high level functionality for rich interaction with the host environtment, all comunications are via function calls with only statically sized numbers and a linear memory, features in wasm were filtered to allow static strict typecheching and performance penalities where accepted where necessary (all memory accesses are bound checked)
My point is that Java applet and wasm are very different. Java applet are like Flash, it is a whole SDK, a programming model, and a separate process that live in a browser plugin.
The main use case of a Java applet is to run a java/JVM application inside an iframe with the motst of the JVM functionality at its disposal (one such feature is runtime reflection so that JVM bytecode is almost impossible to sandbox).
Sandboxing the JVM is close in complexity as sandboxing C: it is going to be hard and ultimately the larger ecosystem will not care about the compromises needed for it to work.
On the other hand wasm mostly tries to just be faster to run. In 2013 Mozilla released asm.js as a subset of javascript that was easier to optimize (it is how it became possible to run demo of unreal engine in javascript). The novelty of this approach was that asm.js was just javascript.
wasm is a continuation of this approach, its sandbox is stronger than Java applet sandbox because wasm is incredibly smaller and it lives inside the same engine as javascript.
Google tried to other way, developing separate plugin languages reserved for browser extensions like NPAPI or PNaCl, I do not know a lot about them, but as far as I understand they mostly worked fine and did not have security issues.
In comparison, wasm apps have their own VM that is embedded into the browser. So there’s nothing extra for users to install (like the jvm). It’s small and lightweight, has (almost) no runtime SDK and it works on phones. I suppose you could write a compiler from C & Rust to Java byte code, ignoring most of the JVM’s features. But that big landscape of exposed features through the JVM still needs to be shipped somehow, and it’s a sandboxing nightmare that wasm just doesn’t have to contend with. Also let’s not forget that Google got sued over their use of Java by Oracle. I don’t want the web of the future to depend on any IP owned by oracle - that sounds like a disaster waiting to happen.
It turns out we want something that is much smaller and much lighter than applets, and is developed as an open collaborative standard from the start.
We also want it built into browsers (so users don't have to install anything else).
Finally, it turns out we don't need it to be able to render directly its own area of the screen - a very non-obvious improvement over applets.
Anything is safer than to run C code directly ;)
The Squoosh CLI has an auto-optimizer that will make an image as small as possible while staying under a given Butteraugli threshold, but you still have to decide on the format yourself.
If you take a 320x image and display it at 320x CSS pixels, it'll look blurry on the vast majority of mobile devices, and a lot of laptops, because 1 CSS pixel is larger than 1 device pixel.
https://developer.mozilla.org/en-US/docs/Web/API/Window/devi...
Fwiw this is covered in the article https://jakearchibald.com/2020/avif-has-landed/#what-is-acce...
I think you should optimise for regular display size and density.
(jake, is that you?)
You seem to be right. Gonna fix the CLI (the CLI is my doing)
Do you express the resulting file size or the amount saved? “30%” could mean you “30% of the original file size” or “you shaved off 30% of the original file size”. You could denote the difference with a sign, like “-30%” but that still confuses people. We ran both options by a lot of our colleagues.
“x% of the original file size” is the least ambiguous, but who has the space to put that entire phrase in their app :-/
How? This doesn't seem to be a problem whenever a shop runs a sale.
You could write "shrunk by/to x%". Or, to stay with the app's theme, "Squooshed by 30%!"
Maybe because they don't mind people misinterpreting the sale as larger? I've never seen 30% off mean "30% of the original price", so if people misinterpret it will always be too small.
If your main goal is to avoid misunderstanding (which it isn't always) then in my opinion it's best not to have anything to do with percentages. Instead, just give the ratio. It might not be elegant, and perhaps some people won't understand it at all, but "0.7x compression" cannot, I think, be misunderstood. (Or can it? I wait to be corrected!)
FWIW I'm not sure what your intended meaning is here. I interpret it to mean that the file got bigger.
Squoosh is available in npm, which should make this pretty easy: https://www.npmjs.com/package/@squoosh/cli
I hope google team also add support for GIF compression, currently I'm using https://gifcompressor.com
Also, it would be convenient if there's a native Windows client which gives the option to select and compress images using context menu itself.
As for animations, video formats with a very low fps are usually way better suited and smaller than GIFs.
What kind of explanation would you like to see? We link to the repo and the Privacy explainer at the bottom of the page. Why is it important to you to know that it’s made by Googlers?
If you mean compress all images in an S3 bucket? Not directly. But we do have a Squoosh CLI!