Skip to content

improving minify can lead to 10kB saved #94

@fab2713

Description

@fab2713

Hi,

Seems that HTML and CSS are nor really minified in the .min.js file.
From my tests with the quick and dirty Python script below, more than 10kB may be saved (from 97260 bytes to 86464 bytes with current overtype version):

import re

with open('overtype.min.js', 'r') as f:
    content = f.read()

def minify_html(match):
    return re.sub(r'[\s\t]+', ' ', re.sub(r'[\n\r]+[\s\t]*', '', match.group(0)))

def minify_css(match):
    return re.sub(r' ?([,;:{}]) ?', '\\1', re.sub(r'[\n\r\s\t]+', ' ', re.sub(r'/\*[^\*]+\*/', '', match.group(0))))

content = re.sub(r'(`[^`]+ class="overtype-stat"[^`]+`)', minify_html, content)
content = re.sub(r'(`[^`]*<svg [^`]+`)', minify_html, content)
content = re.sub(r'(`[^`]+ @media [^`]+`)', minify_css, content)
content = re.sub(r'(`[^`]+/\*[^`]+\*/[^`]+`)', minify_css, content)
content = re.sub(r'(`[^`]+/\*[^`]+\*/[^`]+`)', minify_css, content)

with open('overtype.min2.js', 'w') as f:
    f.write(content)

Feel free to adapt this or not.

Thanks for your work on this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions