soranoo / next-css-obfuscator

A package deeply inspired by PostCSS-Obfuscator but for Next.js.
https://next-css-obfuscator.vercel.app
MIT License
71 stars 3 forks source link

[Feature Request] Alphabetic class names for reduced CSS file size #26

Closed FadyAmir223 closed 6 months ago

FadyAmir223 commented 6 months ago

Checklist

  1. [x] Read all documentation
  2. [x] No related request
  3. [x] Meaningful issue title

Is your feature request related to a problem? Please describe. just a feature request.

Describe the solution you'd like I was inspired by this idea by medium as they don't obfuscate just to hide class names and make the life more hard for web scrapers but also reduce the total css file size by replacing classes with one character (or more when exceed 26).

I guess the modification would to keep track of alphabets outside this function instead of genegating a simple random prefix:

function simplifyString(str: string, seed?: string, rngStateCode?: string) {
  // ...
  const tempStr = str.replace(/[aeiouw\d_-]/gi, "");

  return {
    rngStateCode: rng.getStateCode(),
    randomString: tempStr.length < 1
      ? String.fromCharCode(Math.floor(rng.random(0, 1, true) * 26) + 97) + tempStr
      : tempStr,
  };
}

Example:

<h1 class='a b'>hello</h1>
.a { backgroundColor: white; }
.b { color: black; }

replacing bg-white and text-black.

soranoo commented 6 months ago

I will take a look at it. It will take some time to implement if I find it is possible (but it seems it would be an easy task) because I've been quite busy in recent weeks.

soranoo commented 6 months ago

[#] Renamed the old "simplify" mode to "simplify-seedable" [+] Added alphabetic simplify mode as "simplify"

This update is now under the canary branch, to gain access to the latest feature npm i -D next-css-obfuscator@beta