Skip to content

Minify tempest/view rendered output #1939

@iamdadmin

Description

@iamdadmin

Description

Simply, at the moment a page rendered by tempest/view can depending on how the developer has built their templates, end up with

  • Extra unnecessary line breaks.

From the last lines of the header,start of body on https:

</script>

    
    
                <link rel="canonical"  href="[https://tempestphp.com/3.x/getting-started/introduction](view-source:https://tempestphp.com/3.x/getting-started/introduction)">
            
    

  
</head>
<body class="relative antialiased flex flex-col grow selection:bg-(--ui-primary)/20 selection:text-(--ui-primary) font-sans text-(--ui-text) bg-(--ui-bg) scheme-light dark:scheme-dark overflow-visible! pr-0! ">
<div class="absolute inset-0 bg-repeat pointer-events-none" style="background-image: url(/noise.svg)">
    <div id="command-palette"></div>
</div>
  • Extra whitespace which is not rendered in browser space (both in the class string and the label text).

From the sidebar on https:

<!-- Chapter list -->
          <ul class="flex flex-col border-s border-(--ui-border)">
            <li class="-ms-px ps-1.5">
              <a class="
                  group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-sm focus:outline-none focus-visible:outline-none hover:text-(--ui-text-highlighted) data-[state=open]:text-(--ui-text-highlighted) transition-colors
                 text-(--ui-text-muted)                "  href="[https://tempestphp.com/3.x/essentials/routing](view-source:https://tempestphp.com/3.x/essentials/routing)"  
                >
                Routing              </a>
            </li>
  • The line indents are also inconsistent, understandably, because each could impart it's own as it's parsed and added.

Proposed solution

I'd suggest that there be a minify function added into tempest/view whether that's something regex-y or whether a third party library is utilised.

The minify function would be aware of the environment.

  • When local we'd leave comments in and return a file that has a reasonable go at indenting files to improve developer experience. Additional debug comments could be added even, to aid troubleshooting, although that I do not suggest is in scope for now, and could be a follow-on.

  • When any of the non-dev environments, staging/qa/prod, it could be returned as a full-minified page, with all extraneous whitespace and comments removed.

  • Static:generate should be updated to assume minified by default, but with a command line switch --no-minify for none at all, and --minimal-minify for the local level of minify.

  • The ability to set or disable minify for all environments via .env maybe TEMPEST_VIEW_MINIFY=on/minimal/off as well as selectively TEMPEST_VIEW_MINIFY_LOCAL, TEMPEST_VIEW_MINIFY_PROD with the most specific taking preference.

Benefits

During dev, the code can be indented cleanly to aid troubleshooting and development.

When prod, the code can be minified simply as a matter of best practice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions