Skip to content

More efficient URL sharing method

Álvaro Cuesta requested to merge alvaro-cuesta/pangrama:new-encoding into master

Comparison:

  • Old style:

    /?a=YSVDMyVBMWJjZGUlQzMlQTlmZ2hpJUMzJUFEamtsbW4lQzMlQjFvJUMzJUIzcHFyc3R1JUMzJUJBJUMzJUJDdnd4eXo%3D&p=RWwlMjB2aWtpbmdvJTIwZmFyZnVsbCVDMyVCMyUzQSUyMCVDMiVBMUNhciVDMyVBMW1iYW5vcyElMjAlQzIlQkZRdWklQzMlQTluJTIwZGlqbyUyMHF1ZSUyMFphbWJpYSUyMGV4aXN0aXIlQzMlQURhJTNGJTIwJUMyJUExU2luJTIwcGluZyVDMyVCQ2lub3MlMkMlMjAlQzMlQjF1cyUyMG5pJTIwaGllbG8hJTIwVCVDMyVCQSUyQyUyMHVuJTIwd2hpc2t5Lg%3D%3D

  • New style:

    /?b=BCB6l1Nwbax8KaK6yHCr3gxgiofAuN7jzAGkgKJqsfeq3q8MxPMplhVTBdYRhHgXHdeTTHbOQEP8&a=AuaTZe9Ax7qrVczdWCEm0SBBCm58EQ&s=FM7EO4Z1BL4acq8kxEKZ2l7VfzTEaFjjByP4Vym99TnaatwVaTZBA4Z9oznz6qg5D65skYfKj34jEtomiF5Pnd7bAUFTj0lOBu0ixWuiM&v=2

~40% reduction in size!

To be resolved:

  • Behavior on missing parameters.

    Currently it replaces empty or missing alphabet/sentence with the default one, to match the original behavior.

    Is this intended?

Some notes:

  • There are tests!
    • I added a test phase to CI, as well as enabling builds on non-master branches (to also tests for correct building). Please check this, I'm pretty bad at CI configuration 🤣
  • The code got a bit more complex (surprisingly less than I thought) so "I won't merge this, I prefer simplicity" is a perfectly fine response to this MR 😛
  • I added a versioning URL param (v=2) to support backwards-compatibility, as well as future-proofing changes.
  • I did not use ., - or _ for the encoding alphabet. Although URL-safe (not escaped to things like %3D), they trigger line breaks, can be confused for Markdown formatting or full-stop by automatic URL detectors, are awkward to copy (via double-click), etc. This is base62 and loses a bit of efficiency (about 0.6% on the example sentence) but I think it's a good tradeoff.
  • Requires polyfills for IE11:
  • Please try to break the URL params! I have some guards against bad/corrupt input, but you never know.
  • Style changes, refactors, suggestions, etc. are welcome.
Edited by Álvaro Cuesta

Merge request reports