qwik
qwik copied to clipboard
feat(playground): compress source code to generate shorter shareable URLs
What is it?
- [x] Feature / enhancement
- [ ] Bug
- [ ] Docs / tests
Description
A previous attempt was made to compress source code files prior to generate the final base64-encoded string for the shareable URL, but it was failing.
The trick needed here to make it work is specifying true as the second argument to strFromU8 and strToU8 functions (relevant section of the fflate docs) to enable encoding to a binary string.
To not break existing playground URLs, when parsing the URL, an error while attempting to decompress the string is captured and the previous approach of simply decoding it is used.
Use cases and why
Here are some comparisons of URL lengths (for the files query param):
Example 1 (larger file)
- Not compressed: 7552 characters
- Compressed: 2664 characters
(64.7% of reduction)
Example 2 (default code)
- Not compressed: 1512 characters
- Compressed: 428 characters
(71.7% of reduction)
Checklist:
- [x] My code follows the developer guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] Added new tests to cover the fix / functionality
Run & review this pull request in StackBlitz Codeflow.
Would we be able to make it so the ?files= querystring param uses the old way, and maybe the better compressed way uses ?f=? Just want to make sure existing links still work.
Looking great, thanks!
Would we be able to make it so the
?files=querystring param uses the old way, and maybe the better compressed way uses?f=? Just want to make sure existing links still work.Looking great, thanks!
Makes sense! I'll implement it. We'll also save some characters when sharing 😅
Great work @voluntadpear!
@adamdbradley I've updated the PR to keep supporting the files key but now generate new URLs with an f key instead.
How about keeping a versioned registry of the default settings/files, so that you can just pass v=17 and it would use the defaults from that version, and the f parameter would override the defaults. That will save a bunch of boilerplate in URLs.
How about keeping a versioned registry of the default settings/files, so that you can just pass v=17 and it would use the defaults from that version, and the
fparameter would override the defaults. That will save a bunch of boilerplate in URLs.
I think it's a good idea. I'll work on that in a separate PR and we can discuss details there. 👍
We can merge this PR independently. It's ready now.
I'd love to see this merged!
Any news if there's anything left for this to be merged @adamdbradley? 🙂
@adamdbradley Will it be possible to merge this to close the issue 👀? Thanks Adam 😊
@voluntadpear I cherry picked your commits and added a dictionary etc in #4839
#4839 got merged, so basically this PR also got merged @voluntadpear :) It can be closed now
Sorry, wasn't aware of this PR Thanks a lot @voluntadpear for this contribution! We recently merged #4839 so the change is included Thanks again to both of you!
Thanks for driving this forward @wmertens!