Sorry, we don't support your browser.  Install a modern browser

Shorter IDs for Kirby blocks#240

I think IDs like e449f739-7f9f-46b4-836f-9c534f7bf88c are unnecessarily large. I know they are UUIDs, but is that really needed? Also, you can’t safely use them as id attributes because they shouldn’t start with a number - you’d have to escape them in CSS selectors.

I think that 8-character IDs always starting with a letter (e.g. adN3bf9e) would be enough. You’d have 52 possibilities for the first character (26 lowercase and 26 uppercase letters) and 62 for the rest (letters + 10 digits). This means:

52 * (62^7) = 183,123,959,522,816

That’s a lot of IDs. I think that 1000 blocks is about as much as you’ll ever have in a field, especially now that a text block can contain multiple paragraps - it’s not like the editor field where each paragraph was a separate block.

If you have 1000 blocks, the possibility of a collision for the 1001-st block is:

1,001 / 183,123,959,522,816 = 0.0000000000054662426% (5.4662426e-12)

I think it would be nicer if IDs are shorter and therefore - your URLs.

3 years ago

I agree, using something like https://github.com/ai/nanoid is both faster, and can achieve the same level of entropy with less characters. There’s a nice PHP implementation and it’s already used (optionally) in the fantastic AutoID plugin (https://github.com/bnomei/kirby3-autoid/blob/master/classes/NanoGenerator.php)

3 years ago

I also think they are to heavy, but that’s ok in my opinion. We use them in the frontend in a modified version like this:

Edit: seems like rough PHP isn’t allowed in Nolt … but we shorten it to 8 characters

3 years ago

You can generate own custom id with block models:
https://github.com/getkirby/kirby/pull/3739

3 years ago
1