{"id":21700138,"url":"https://github.com/wp-digital/wp-prerender-aws-lambda","last_synced_at":"2025-04-12T13:23:17.365Z","repository":{"id":56991720,"uuid":"280410941","full_name":"wp-digital/wp-prerender-aws-lambda","owner":"wp-digital","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-21T11:59:58.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-08T18:49:07.817Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-digital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-17T11:49:28.000Z","updated_at":"2022-01-06T18:36:11.000Z","dependencies_parsed_at":"2022-08-21T12:20:40.645Z","dependency_job_id":null,"html_url":"https://github.com/wp-digital/wp-prerender-aws-lambda","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-digital%2Fwp-prerender-aws-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-digital%2Fwp-prerender-aws-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-digital%2Fwp-prerender-aws-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-digital%2Fwp-prerender-aws-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-digital","download_url":"https://codeload.github.com/wp-digital/wp-prerender-aws-lambda/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248572095,"owners_count":21126583,"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":"2024-11-25T20:13:00.399Z","updated_at":"2025-04-12T13:23:17.330Z","avatar_url":"https://github.com/wp-digital.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Lambda Prerender\n\n### Description\n\nGenerates HTML for client-side rendered content via AWS Lambda. This plugin sends request\nto [AWS Lambda Prerender](https://github.com/innocode-digital/aws-lambda-prerender) function\nwhich renders content with [Puppeteer](https://github.com/puppeteer/puppeteer) and returns\nHTML back through REST API callback.\n\n### Install\n\n- Preferable way is to use [Composer](https://getcomposer.org/):\n\n    ````\n    composer require innocode-digital/wp-prerender-aws-lambda\n    ````\n  \n  By default, it will be installed as [Must Use Plugin](https://codex.wordpress.org/Must_Use_Plugins).\n  It's possible to control with `extra.installer-paths` in `composer.json`.\n\n- Alternate way is to clone this repo to `wp-content/mu-plugins/` or `wp-content/plugins/`:\n\n    ````\n    cd wp-content/plugins/\n    git clone git@github.com:innocode-digital/wp-prerender-aws-lambda.git\n    cd wp-prerender-aws-lambda/\n    composer install\n    ````\n\nIf plugin was installed as regular plugin then activate **AWS Lambda Prerender** from Plugins page\nor [WP-CLI](https://make.wordpress.org/cli/handbook/): `wp plugin activate wp-prerender-aws-lambda`.\n\n### Configuration\n\nAdd the following constants to `wp-config.php`:\n\n````\ndefine( 'AWS_LAMBDA_PRERENDER_KEY', '' );\ndefine( 'AWS_LAMBDA_PRERENDER_SECRET', '' );\ndefine( 'AWS_LAMBDA_PRERENDER_REGION', '' ); // e.g. eu-west-1\n\ndefine( 'AWS_LAMBDA_PRERENDER_FUNCTION', '' ); // Optional, default value is \"prerender-production-render\"\n````\n\nCreate Lambda function on AWS. Expected default name is **prerender-production-render**\nbut you may use any other. There is a prepared function [AWS Lambda Prerender](https://github.com/innocode-digital/aws-lambda-prerender).\n\nUsed user should have `InvokeFunction` in policy.\n\n---\n\n````\ndefine( 'AWS_LAMBDA_PRERENDER_DB_TABLE', '' ); // Optional, default value is \"innocode_prerender\"\n\ndefine( 'AWS_LAMBDA_PRERENDER_QUERY_ARG', '' ); // Optional, default value is \"innocode_prerender\"\n````\n\nIt's possible to change database table name where HTML will be stored and query argument\nwhich is using when serverless function makes request to website.\n\n### Usage\n\nPlugin automatically generates HTML on Post/Page and Term save action with updating of\nrelated content like Frontpage, but it's possible to control this behavior e.g. if you do not\nwant to update author's archive page on post save then use next filter:\n\n````\nadd_filter( 'innocode_prerender_should_update_post_author', function (\n    (bool) $should_update,\n    int $object_id,\n    $id\n) : bool {\n    // Do not update achive page of author with user id 5.\n    if ( $id == 5 ) {\n        return false;\n    }\n\n    return $should_update;\n}, 10, 3 );\n````\n\nAlso, plugin generates HTML \"on the fly\" when someone visits any of object with [template](#existing-templates)\ne.g. single post and if there is no content in database for current object in current\nversion then cron task will be scheduled to make new request to Lambda.\n\nIf theme does not support e.g. date archives then it's possible to disable them at all:\n\n````\nadd_filter( 'innocode_prerender_template', function ( string $template ) : string {\n    if ( $template == 'date_archive' ) {\n        return '';\n    }\n\n    return $template;\n} );\n````\n\nAlso, it's possible to add custom template in addition to [existing](#existing-templates):\n\n1. Create new template from `Innocode\\Prerender\\Abstracts\\AbstractTemplate` class:\n\n````\n...\nuse Innocode\\Prerender\\Abstracts\\AbstractTemplate;\n\nclass YourTemplate extends AbstractTemplate\n{\n    ...\n}\n````\n\n2. Implement method stubs in your template class.\n3. Add your template class object to templates collection:\n\n````\n$your_template = new YourTemplate();\ninnocode_prerender()-\u003einsert_templates( [ $your_template ] );\n````\n\nBy default, plugin uses selector `#app` to grab content, i.e. that your client-side\napplication is wrapped in block with ID `app`:\n\n````\n\u003cdiv id=\"app\"\u003e\u003c/div\u003e\n````\n\nIf it's needed to change selector use next hook:\n\n````\nadd_filter( 'innocode_prerender_selector', function () : string {\n    return '#main';\n} )\n````\n\n### Notes\n\n#### Existing templates\n\n- `post` - Post, Page and Custom Post Type\n- `term` - Category, Tag and Custom Taxonomy Term\n- `author` - Author Archive\n- `frontpage` - Front Page\n- `post_type_archive` - Post Type Archive\n- `date_archive` - Year, Month and Day Archives\n\n#### Version\n\nIt was mentioned above that content has a version, and you may want to upgrade it at some\npoint, most obvious case when something has been changed in client-side rendered layout.\nIn this case it's needed to bump new version:\n\n````\nif ( function_exists( 'innocode_prerender' ) ) {\n    innocode_prerender()\n        -\u003eget_db()\n        -\u003eget_html_version()\n        -\u003ebump();\n}\n````\n\nBut, you can install [Flush Cache Buttons](https://github.com/innocode-digital/wp-flush-cache)\nplugin which adds possibility to do this action by clicking on the button in admin panel.\n\n#### Modify content during prerendering\n\nSometimes content which is prerendered should be different from what we get on client-side\ne.g. you may need to exclude certain element. In this case use JavaScript global variable:\n\n````\nif (window.__INNOCODE_PRERENDER__) {\n    // Only for prerendering.\n} else {\n    // Only for client-side.\n}\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-digital%2Fwp-prerender-aws-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-digital%2Fwp-prerender-aws-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-digital%2Fwp-prerender-aws-lambda/lists"}