{"id":20134407,"url":"https://github.com/wearerequired/h2push","last_synced_at":"2025-04-09T17:20:42.419Z","repository":{"id":27351178,"uuid":"106005391","full_name":"wearerequired/h2push","owner":"wearerequired","description":"Sends Link headers to bring HTTP/2 Server Push for scripts and styles to WordPress.","archived":false,"fork":false,"pushed_at":"2024-03-01T03:05:38.000Z","size":84,"stargazers_count":5,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T19:22:12.874Z","etag":null,"topics":["wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","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/wearerequired.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-06T13:03:48.000Z","updated_at":"2024-03-30T00:49:10.000Z","dependencies_parsed_at":"2024-01-12T00:25:38.274Z","dependency_job_id":"1acb0ae8-db45-4758-b5d8-195437e5afa1","html_url":"https://github.com/wearerequired/h2push","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearerequired%2Fh2push","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearerequired%2Fh2push/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearerequired%2Fh2push/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearerequired%2Fh2push/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wearerequired","download_url":"https://codeload.github.com/wearerequired/h2push/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838443,"owners_count":21004580,"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":["wordpress","wordpress-plugin"],"created_at":"2024-11-13T21:09:27.525Z","updated_at":"2025-04-09T17:20:42.388Z","avatar_url":"https://github.com/wearerequired.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP/2 Server Push\n\n[![PHPUnit Tests](https://github.com/wearerequired/h2push/actions/workflows/phpunit-tests.yml/badge.svg)](https://github.com/wearerequired/h2push/actions/workflows/phpunit-tests.yml) [![Coding Standards](https://github.com/wearerequired/h2push/actions/workflows/coding-standards.yml/badge.svg)](https://github.com/wearerequired/h2push/actions/workflows/coding-standards.yml)\n\nSends Link headers to bring HTTP/2 Server Push for scripts and styles to WordPress. Falls back to `\u003clink\u003e` element if headers are already sent.  \nProvides filters to customize and extend the resources to push.\n\n![Screenshot](https://user-images.githubusercontent.com/617637/31279476-7c3dffd6-aaa9-11e7-91d8-57ec4435d067.png)\n\n## Installation\n\nInstall the latest version with\n\n```sh\ncomposer require wearerequired/h2push\n```\n\nThe plugin requires at least PHP 7.4 and WordPress 5.6.\n\n## Hooks reference\n\n### `h2push.as_header`\n\nBy default the plugin will use the Link header if no headers are sent yet and falls back to the `\u003clink\u003e` element. To change this behavior you can use the `h2push.as_header` filter. Example:\n\n```php\n// Force H2 Push to always use the `\u003clink\u003e` element.\nadd_filter( 'h2push.as_header', '__return_false' );\n```\n\nThis filter is also useful if the server doesn't support HTTP/2 yet and you still want to benefit from preloading.\n\n### `h2push.push_resources`\n\nBy default the plugin collects all enqueued scripts and styles which are have been registered before or at the `wp_enqueue_scripts` hook. The `h2push.push_resources` filters allows to customize the list of resources. Example:\n\n```php\n/**\n * Add web font and hero image to the list of resources to push/preload.\n *\n * @param array $resources List of resources.\n * @return array List of resources.\n */\nfunction my_theme_push_resources( array $resources ): array {\n\t$relative_template_directory_uri = wp_parse_url( get_template_directory_uri(), PHP_URL_PATH );\n\n\t// Push web font.\n\t$resources[] = [\n\t\t'href' =\u003e $relative_template_directory_uri . '/assets/fonts/fancy.woff2',\n\t\t'as'   =\u003e 'font',\n\t\t'type' =\u003e 'font/woff2',\n\t\t'crossorigin',\n\t];\n\n\tif ( is_front_page() \u0026\u0026 ! is_paged() ) {\n\t\t// Push hero image.\n\t\t$resources[] = [\n\t\t\t'href' =\u003e $relative_template_directory_uri . '/assets/images/hero.webp',\n\t\t\t'as'   =\u003e 'image',\n\t\t\t'type' =\u003e 'image/webp',\n\t\t];\n\t}\n\n\treturn $resources;\n}\nadd_filter( 'h2push.push_resources', 'my_theme_push_resources' );\n```\n\n### `h2push.is_allowed_push_host`\n\nBy default the plugin only sends push requests for local resources where the asset URL matches the home URL. To change this behavior you can use the `h2push.is_allowed_push_host` filter. Example:\n\n```php\n/**\n * Allow resources from example.org to be pushed/preloaded too.\n *\n * @param bool   $is_allowed Whether the host should be allowed. Default true for local resources.\n * @param string $host       The host name of the resource.\n * @return bool Whether the host should be allowed.\n */\nfunction my_theme_is_allowed_push_host( $is_allowed, $host ) {\n\treturn $is_allowed || 'example.org' === $host;\n}\nadd_filter( 'h2push.is_allowed_push_host', 'my_theme_is_allowed_push_host' );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearerequired%2Fh2push","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwearerequired%2Fh2push","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearerequired%2Fh2push/lists"}