{"id":27629568,"url":"https://github.com/markjaquith/encute","last_synced_at":"2025-04-23T15:26:53.393Z","repository":{"id":62524203,"uuid":"414662625","full_name":"markjaquith/encute","owner":"markjaquith","description":"WordPress plugin for fluent management of scripts and styles.","archived":false,"fork":false,"pushed_at":"2022-02-17T20:28:35.000Z","size":1988,"stargazers_count":107,"open_issues_count":1,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-17T14:42:48.306Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markjaquith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-07T15:45:29.000Z","updated_at":"2024-01-25T13:06:01.000Z","dependencies_parsed_at":"2022-11-02T15:30:57.634Z","dependency_job_id":null,"html_url":"https://github.com/markjaquith/encute","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2Fencute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2Fencute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2Fencute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2Fencute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markjaquith","download_url":"https://codeload.github.com/markjaquith/encute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250459136,"owners_count":21434027,"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":[],"created_at":"2025-04-23T15:26:52.764Z","updated_at":"2025-04-23T15:26:53.367Z","avatar_url":"https://github.com/markjaquith.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Encute\n\nWordPress plugin for fluent management of scripts and styles.\n\nManaging scripts and styles on the front of your site can be tricky. This makes it trivial to do stuff like:\n\n- Shove a script (and its entire connected family) into the footer\n- Defer a script or a style until page load\n- Load a script `async`\n- Mark a script as `type=\"module\"`\n- Mark a script as `nomodule`\n- Remove some plugin script or style you don't need\n\n## Installation\n\nIf you're using composer you can `composer require markjaquith/encute`. Else, install via Git.\n\n## Usage\n\nPut this in an `mu-plugins` drop-in:\n\n```php\n\u003c?php\n\nuse CWS\\Encute\\Plugin;\nuse CWS\\Encute\\Script;\nuse CWS\\Encute\\Style;\n\nadd_action(Plugin::class, function (Plugin $encute) {\n\t$encute-\u003edebug(); // Optional: Adds HTML comments to scripts and styles, making it easier to see the handle.\n\n\t// Move jQuery to footer and defer its loading.\n\tScript::get('jquery')-\u003efooter()-\u003edefer();\n\n\t// Move 'some-handle' to the footer.\n\tScript::get('some-handle')-\u003efooter();\n\n\t// Defer 'wp-embed'.\n\tScript::get('wp-embed')-\u003edefer();\n\t\n\t// Make 'some-module' load as a module.\n\tScript::get('some-module')-\u003emodule();\n\t\n\t// Make 'nomodule-fallback' load as nomodule.\n\tScript::get('nomodule-fallback')-\u003enoModule();\n\t\n\t// Move 'admin-bar' styles to the footer and defer their loading.\n\tStyle::get('admin-bar')-\u003efooter()-\u003edefer();\n\n\t// Move 'wp-block-library' styles to the footer.\n\tStyle::get('wp-block-library')-\u003efooter();\n\n\t// Keep 'contact-form-7' style on contact page only.\n\tStyle::get('contact-form-7')-\u003ekeepIf(fn() =\u003e is_page('contact'));\n\n\t// Remove 'cruft' script on the about page.\n\tScript::get('cruft')-\u003eremoveIf(fn() =\u003e is_page('about'));\n});\n```\n\n## API\n\n### Initialization\n\nAlways run code in this wrapper:\n\n```php\nadd_action(\\CWS\\Encute\\Plugin::class, function (\\CWS\\Encute\\Plugin $encute) {\n\t// Your code here.\n});\n```\n\nThis wrapper will be a no-op if Encute is not available, and it will both wait for Encute to be available to run, and pass you Encute's main class instance.\n\n### Fluency\n\n`Script::get()` and `Style::get()` return an instance of themselves, as do all calls to their methods, so you can just chain your calls.\n\n### Script\n\n- `static CWS\\Encute\\Script::get(string $handle): CWS\\Encute\\Script` — get a Script instance for that handle.\n- `CWS\\Encute\\Script::module(): CWS\\Encute\\Script` — make the script a module.\n- `CWS\\Encute\\Script::noModule(): CWS\\Encute\\Script` — make the script nomodule.\n- `CWS\\Encute\\Script::footer(): CWS\\Encute\\Script` — send the script to the footer (along with its entire dependency family).\n- `CWS\\Encute\\Script::async(): CWS\\Encute\\Script` — make the script async.\n- `CWS\\Encute\\Script::defer(): CWS\\Encute\\Script` — make the script defer.\n- `CWS\\Encute\\Script::remove(): CWS\\Encute\\Script` — remove the script.\n- `CWS\\Encute\\Script::removeIf(callable $callback): CWS\\Encute\\Script` — remove the script if the callback resolves as true.\n- `CWS\\Encute\\Script::keepIf(callable $callback): CWS\\Encute\\Script` — keep the script if the callback resolves as true (else remove it).\n\n### Style\n\n- `static CWS\\Encute\\Style::get(string $handle): CWS\\Encute\\Style` — get a Style instance for that handle.\n- `CWS\\Encute\\Style::footer(): CWS\\Encute\\Style` — send the style to the footer (along with its entire dependency family).\n- `CWS\\Encute\\Style::defer(): CWS\\Encute\\Style` — defer the style's loading.\n- `CWS\\Encute\\Style::remove(): CWS\\Encute\\Style` — remove the style.\n- `CWS\\Encute\\Style::removeIf(callable $callback): CWS\\Encute\\Style` — remove the style if the callback resolves as true.\n- `CWS\\Encute\\Style::keepIf(callable $callback): CWS\\Encute\\Style` — keep the style if the callback resolves as true (else remove it).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkjaquith%2Fencute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkjaquith%2Fencute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkjaquith%2Fencute/lists"}