innocode-digital/wp-prerender-aws-lambda
Composer 安装命令:
composer require innocode-digital/wp-prerender-aws-lambda
包简介
Generates HTML for client-side rendered content via AWS Lambda.
关键字:
README 文档
README
Description
Generates HTML for client-side rendered content via AWS Lambda. This plugin sends request to AWS Lambda Prerender function which renders content with Puppeteer and returns HTML back through REST API callback.
Install
-
Preferable way is to use Composer:
composer require innocode-digital/wp-prerender-aws-lambdaBy default, it will be installed as Must Use Plugin. It's possible to control with
extra.installer-pathsincomposer.json. -
Alternate way is to clone this repo to
wp-content/mu-plugins/orwp-content/plugins/:cd wp-content/plugins/ git clone git@github.com:innocode-digital/wp-prerender-aws-lambda.git cd wp-prerender-aws-lambda/ composer install
If plugin was installed as regular plugin then activate AWS Lambda Prerender from Plugins page
or WP-CLI: wp plugin activate wp-prerender-aws-lambda.
Configuration
Add the following constants to wp-config.php:
define( 'AWS_LAMBDA_PRERENDER_KEY', '' );
define( 'AWS_LAMBDA_PRERENDER_SECRET', '' );
define( 'AWS_LAMBDA_PRERENDER_REGION', '' ); // e.g. eu-west-1
define( 'AWS_LAMBDA_PRERENDER_FUNCTION', '' ); // Optional, default value is "prerender-production-render"
Create Lambda function on AWS. Expected default name is prerender-production-render but you may use any other. There is a prepared function AWS Lambda Prerender.
Used user should have InvokeFunction in policy.
define( 'AWS_LAMBDA_PRERENDER_DB_TABLE', '' ); // Optional, default value is "innocode_prerender"
define( 'AWS_LAMBDA_PRERENDER_QUERY_ARG', '' ); // Optional, default value is "innocode_prerender"
It's possible to change database table name where HTML will be stored and query argument which is using when serverless function makes request to website.
Usage
Plugin automatically generates HTML on Post/Page and Term save action with updating of related content like Frontpage, but it's possible to control this behavior e.g. if you do not want to update author's archive page on post save then use next filter:
add_filter( 'innocode_prerender_should_update_post_author', function (
(bool) $should_update,
int $object_id,
$id
) : bool {
// Do not update achive page of author with user id 5.
if ( $id == 5 ) {
return false;
}
return $should_update;
}, 10, 3 );
Also, plugin generates HTML "on the fly" when someone visits any of object with template e.g. single post and if there is no content in database for current object in current version then cron task will be scheduled to make new request to Lambda.
If theme does not support e.g. date archives then it's possible to disable them at all:
add_filter( 'innocode_prerender_template', function ( string $template ) : string {
if ( $template == 'date_archive' ) {
return '';
}
return $template;
} );
Also, it's possible to add custom template in addition to existing:
- Create new template from
Innocode\Prerender\Abstracts\AbstractTemplateclass:
...
use Innocode\Prerender\Abstracts\AbstractTemplate;
class YourTemplate extends AbstractTemplate
{
...
}
- Implement method stubs in your template class.
- Add your template class object to templates collection:
$your_template = new YourTemplate();
innocode_prerender()->insert_templates( [ $your_template ] );
By default, plugin uses selector #app to grab content, i.e. that your client-side
application is wrapped in block with ID app:
<div id="app"></div>
If it's needed to change selector use next hook:
add_filter( 'innocode_prerender_selector', function () : string {
return '#main';
} )
Notes
Existing templates
post- Post, Page and Custom Post Typeterm- Category, Tag and Custom Taxonomy Termauthor- Author Archivefrontpage- Front Pagepost_type_archive- Post Type Archivedate_archive- Year, Month and Day Archives
Version
It was mentioned above that content has a version, and you may want to upgrade it at some point, most obvious case when something has been changed in client-side rendered layout. In this case it's needed to bump new version:
if ( function_exists( 'innocode_prerender' ) ) {
innocode_prerender()
->get_db()
->get_html_version()
->bump();
}
But, you can install Flush Cache Buttons plugin which adds possibility to do this action by clicking on the button in admin panel.
Modify content during prerendering
Sometimes content which is prerendered should be different from what we get on client-side e.g. you may need to exclude certain element. In this case use JavaScript global variable:
if (window.__INNOCODE_PRERENDER__) {
// Only for prerendering.
} else {
// Only for client-side.
}
innocode-digital/wp-prerender-aws-lambda 适用场景与选型建议
innocode-digital/wp-prerender-aws-lambda 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugins」 「wordpress」 「prerender」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 innocode-digital/wp-prerender-aws-lambda 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 innocode-digital/wp-prerender-aws-lambda 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 innocode-digital/wp-prerender-aws-lambda 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel middleware for prerendering javascript-rendered pages on the fly for SEO
Laravel middleware for prerendering javascript-rendered pages on the fly for SEO
Crawl your own website with various clients for SEO and indexing purposes.
Laravel middleware for prerendering javascript-rendered pages on the fly for SEO
Laravel middleware for prerendering javascript-rendered pages on the fly for SEO
Prerender
统计信息
- 总下载量: 2.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2021-12-08