{"id":21429375,"url":"https://github.com/nystudio107/minify","last_synced_at":"2025-05-12T14:29:13.845Z","repository":{"id":57029562,"uuid":"46609630","full_name":"nystudio107/minify","owner":"nystudio107","description":"DEPRECATED A simple plugin that allows you to minify blocks of HTML, CSS, and JS inline in Craft CMS templates","archived":false,"fork":false,"pushed_at":"2019-01-01T23:38:13.000Z","size":1429,"stargazers_count":107,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-12T14:29:04.244Z","etag":null,"topics":["craft-plugin","craftcms","deprecated","minify"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nystudio107.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-21T09:45:48.000Z","updated_at":"2023-12-13T00:19:40.000Z","dependencies_parsed_at":"2022-08-23T17:40:53.936Z","dependency_job_id":null,"html_url":"https://github.com/nystudio107/minify","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fminify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fminify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fminify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nystudio107%2Fminify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nystudio107","download_url":"https://codeload.github.com/nystudio107/minify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754699,"owners_count":21958897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["craft-plugin","craftcms","deprecated","minify"],"created_at":"2024-11-22T22:17:29.257Z","updated_at":"2025-05-12T14:29:13.817Z","avatar_url":"https://github.com/nystudio107.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n# DEPRECATED\n\nThis Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.\n\nThe Craft CMS 3.x version of this plugin can be found here: [craft-minify](https://github.com/nystudio107/craft-minify) and can also be installed via the Craft Plugin Store in the Craft CP.\n\n# Minify plugin for Craft CMS\n\nA simple plugin that allows you to minify blocks of HTML, CSS, and JS inline in Craft CMS templates\n\nRelated: [Minify for Craft 3.x](https://github.com/nystudio107/craft3-minify)\n\n**Installation**\n\n1. Download \u0026 unzip the file and place the `minify` directory into your `craft/plugins` directory\n2.  -OR- do a `git clone https://github.com/khalwat/minify.git` directly into your `craft/plugins` folder.  You can then update it with `git pull`\n3.  -OR- install with Composer via `composer require nystudio107/minify`\n4. Install plugin in the Craft Control Panel under Settings \u003e Plugins\n5. The plugin folder should be named `minify` for Craft to see it.  GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.\n\n## Configuring Minify\n\nThere is nothing to configure\n\n## Using the Minify plugin in your templates\n\nMinify adds several block tags for minifying HTML, CSS, and JS inline in your templates.  Minify does **not** minify external CSS or JS files.  Use `grunt` or `gulp` task runners to set up a workflow that minimizes these as part of your build process.\n\nYou can nest any number of the various `{% minify %}` tags as you wish.\n\n## Why minify inline HTML/CSS/JS code?\n\nTwig provides the `{% spaceless %}` tag, but it is not intended for use as a way to properly minify HTML/CSS/JS code.\n\nYou already properly `gzip` output via `mod_deflate` with Apache or by enabling compression with `Nginx` for optimal delivery on production.  You already use a task runner like `grunt` or `gulp` or CodeKit to minimize static resources like CSS/JS files.  What's the point of minifying HTML/CSS/JS inline?\n\nFirstly, you want to keep HTML/CSS/JS comments and a nice hierarchical structure to your code, with plenty of readable whitespace for development, but want all of this stripped out of the HTML/CSS/JS that is served to your frontend.\n\nSecondly, not all CSS/JS can or should be in static asset files.  Sometimes you need inline Javascript for efficiency reasons, or if you're using `JSON-LD` for Google Structured Data/SEO purposes inline in your HTML files.  You may also want to be able to use the Craft templating engine in your CSS/JS itself.\n\nFinally, if you minify any code you wrap in `{% cache %}` tags, that means it will be stored minified in the database, reducing db size and (marginally) transactional overhead.\n\n### Minifying Everything\n\nYou can wrap any arbitrary HTML/Twig code in the following block tags to minify it:\n\n\t{% minify %}\n\t\t(HTML/Twig code here)\n    {% endminify %}\n\n...and the resulting HTML output will be stripped of comments, empty space, etc.\n\nUsing the `{% minify %}` on its own with no parameters (see below) will minify HTML, as well as any inline CSS (in `\u003cstyle\u003e` tag pairs) and any inline Javascript (in `\u003cscript\u003e` tag pairs).\n\n\n### Minifying HTML\n\nYou can wrap any arbitrary HTML/Twig code in the following block tags to minify it:\n\n\t{% minify html %}\n\t\t(HTML/Twig code here)\n    {% endminify %}\n\n...and the resulting HTML output will be stripped of comments, empty space, etc.\n\nIt will ignore `\u003cscript\u003e` and `\u003cstyle\u003e` tag pairs in the minification.  You should specifically wrap your inline CSS/JS in `{% minify css %}` and `{% minify js}` tag blocks if you want those minimized as well; see below.\n\n### Minifying CSS\n\nYou can wrap any arbitrary `\u003cstyle\u003e` CSS code in the following block tags to minify it:\n\n\t{% minify css %}\n \t\t\u003cstyle\u003e\n \t\t\t(Inline CSS styles here)\n\t\t\u003c/style\u003e\n\t{% endminify %}\n\n...and the resulting CSS output will be stripped of comments, empty space, etc.\n    \n### Minifying JS\n\nYou can wrap any arbitrary `\u003cscript\u003e` JS code in the following block tags to minify it:\n\n\t{% minify js %}\n \t\t\u003cscript\u003e\n \t\t\t(Inline JS code here)\n \t\t\u003c/script\u003e\n    {% endminify %}\n\n...and the resulting JS output will be stripped of comments, empty space, etc.\n    \n## Minify all the things\n\nIf you want to minify your entire HTML on the frontend, you can simply wrap your entire `_layout.twig` template (the one that other templates `extends`):\n\n\t{% minify %}\n\t\t\t(Entire base HTML/Twig template here)\n    {% endminify %}\n\nHowever, understand the potential performance implications.  On large HTML/CSS/JS blocks minification is not cheap, and if you do it this way, every single HTTP request will spend extra cycles minimizing your entire template.\n\nIt works fine for HTML/CSS/JS templates that aren't too huge, but measure any performance impact by profiling your website before and after wrapping the entire `_layout.twig` template to ensure you're not introducing additional latency in the http requests.\n\nOn most sites, the overhead that spinning up PHP and Craft takes is the majority of the TTFB (Time To First Byte), and this is not adversely affected by minifying the entire HTML as described here.\n\n## Cache as cache can\n\nA great way to use the `{% minify %}` tags is to wrap them in `{% cache %}` tags:\n\n\t{% cache %}\n\t\t{% minify %}\n\t\t\t(HTML/Twig code here)\n    \t{% endminify %}\n    {% endcache %}\n\nAs with `{% cache %}` tags, you can’t use `{% minify %}` tags outside of top-level `{% block %}` tags within a template that extends another.  [Read more about cache tags](http://buildwithcraft.com/docs/templating/cache)\n\nA nice side-benefit of minifying HTML inside of `{% cache %}` tags is that the text that is stored in the database as a cache is minified itself.\n\nIf you've already implemented a caching system to reduce server response time, adding `{% minify %}` tags to the mix is a natural.\n\n## Minify craft.config settings\n\nMinify offers two `craft.config` (set in your `config/general.php`) to allow you to control its behavior:\n\n`disableTemplateMinifying` if set to `true` then Minify will not minify anything\n\n`disableDevmodeMinifying` if set to `true` then Minify will not minify anything if `devMode` is enabled\n\n## Why does my minified HTML/CSS still have linebreaks?\n\nMinify uses the [Minify PHP library](https://github.com/mrclay/minify).  Here's their official explanation:\n\n#### Why do the CSS \u0026 HTML minifiers add so many line breaks?\nTL;DR: Ignore them. They don't add to the output size and if you absolutely want all content on one line you will have to use another tool.\n\nIt's rumored that some source control tools and old browsers don't like very long lines. Compressed files with shorter lines are also easier to diff.\n\nSince both Minify classes are regex-based, it would be very difficult/error-prone to count characters then try to re-establish context to add line breaks. Instead, both classes trade 1 space for 1 line break (\\n) wherever possible, adding breaks but without adding bytes.\n\nIf you can think of another safe \u0026 efficient way to limit lines in these two tools without adding bytes, please submit a patch, but this is not something anyone should be worrying about.\n\nBrought to you by [nystudio107](http://nystudio107.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnystudio107%2Fminify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnystudio107%2Fminify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnystudio107%2Fminify/lists"}