qwik icon indicating copy to clipboard operation
qwik copied to clipboard

feat(playground): compress source code to generate shorter shareable URLs

Open voluntadpear opened this issue 3 years ago • 9 comments
trafficstars

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

voluntadpear avatar Nov 02 '22 02:11 voluntadpear

Review PR in StackBlitz Codeflow 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!

adamdbradley avatar Nov 02 '22 14:11 adamdbradley

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 😅

voluntadpear avatar Nov 02 '22 16:11 voluntadpear

Great work @voluntadpear!

nnelgxorz avatar Nov 02 '22 17:11 nnelgxorz

@adamdbradley I've updated the PR to keep supporting the files key but now generate new URLs with an f key instead.

voluntadpear avatar Nov 02 '22 21:11 voluntadpear

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.

wmertens avatar Nov 03 '22 08:11 wmertens

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.

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.

voluntadpear avatar Nov 03 '22 13:11 voluntadpear

I'd love to see this merged!

wmertens avatar Nov 15 '22 07:11 wmertens

Any news if there's anything left for this to be merged @adamdbradley? 🙂

voluntadpear avatar Nov 15 '22 12:11 voluntadpear

@adamdbradley Will it be possible to merge this to close the issue 👀? Thanks Adam 😊

noeliadv avatar Jun 29 '23 18:06 noeliadv

@voluntadpear I cherry picked your commits and added a dictionary etc in #4839

wmertens avatar Jul 22 '23 10:07 wmertens

#4839 got merged, so basically this PR also got merged @voluntadpear :) It can be closed now

wmertens avatar Jul 25 '23 12:07 wmertens

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!

shairez avatar Jul 25 '23 13:07 shairez

Thanks for driving this forward @wmertens!

voluntadpear avatar Jul 25 '23 13:07 voluntadpear