Calculates the byte size of a string using UTF-8 encoding.
This function is used to determine the size of payloads before sending them to ensure they don't exceed browser limits for beacon requests.
The string to calculate the byte size for
The number of bytes the string occupies when encoded as UTF-8
const size = sizeOf("Hello, World!"); // Returns 13const largeSize = sizeOf(JSON.stringify(largeObject)); Copy
const size = sizeOf("Hello, World!"); // Returns 13const largeSize = sizeOf(JSON.stringify(largeObject));
Calculates the byte size of a string using UTF-8 encoding.
This function is used to determine the size of payloads before sending them to ensure they don't exceed browser limits for beacon requests.