From 1d524d4d6e052e02d2ba69868b52ff33fd1df253 Mon Sep 17 00:00:00 2001 From: Josh Bruce Date: Wed, 1 Dec 2021 22:16:53 -0600 Subject: [PATCH 1/2] feat: Lazy loading and async decoding of images --- site-dynamic-php/src/Content/Markdown.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/site-dynamic-php/src/Content/Markdown.php b/site-dynamic-php/src/Content/Markdown.php index e625555a..83e5a8cb 100644 --- a/site-dynamic-php/src/Content/Markdown.php +++ b/site-dynamic-php/src/Content/Markdown.php @@ -4,6 +4,8 @@ namespace JoshBruce\SiteDynamic\Content; +use League\CommonMark\Extension\CommonMark\Node\Inline\Image; + use Eightfold\Markdown\Markdown as MarkdownConverter; use JoshBruce\SiteDynamic\Environment; @@ -44,16 +46,21 @@ public static function markdownConverter(): MarkdownConverter ->smartPunctuation() ->descriptionLists() ->attributes() // for class on notices - ->abbreviations() + ->defaultAttributes([ + Image::class => [ + 'loading' => 'lazy', + 'decoding' => 'async' + ] + ])->abbreviations() ->externalLinks( [ 'open_in_new_window' => true, - 'internal_hosts' => 'joshbruce.com' + 'internal_hosts' => 'joshbruce.com' ] )->accessibleHeadingPermalinks( [ 'min_heading_level' => 2, - 'symbol' => '#' + 'symbol' => '#' ], ); } From a758ee43367e9f614bfb9129e8ee6b4f7e6b3b12 Mon Sep 17 00:00:00 2001 From: Josh Bruce Date: Wed, 1 Dec 2021 22:17:11 -0600 Subject: [PATCH 2/2] update: This site 2021 --- .../web-development/this-site/2021/content.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/content/public/web-development/this-site/2021/content.md b/content/public/web-development/this-site/2021/content.md index 2807ce85..56ded070 100644 --- a/content/public/web-development/this-site/2021/content.md +++ b/content/public/web-development/this-site/2021/content.md @@ -193,6 +193,60 @@ I will use three categories or styles of pages: 2. long content with media. 3. long content with third-party integrations - should be difficult to find one of these. +### December 1st, 2021 + +Waiting for response: ~50ms. (opcache in place, with timestamp checking enabled). + +1. https://joshbruce.com (short content, minimal assets and media) +2. https://joshbruce.com/web-development/this-site/2021/ (long content, images) +3. https://joshbruce.com/web-development/on-constraints/internet-bandwidth/ (long content) + +- Dynamic content generation: Once the site is running, it SHOULD return a response in less than 150ms. +- [web.dev](https://web.dev/measure/): All stats (except PWA) SHOULD be greater than 95 percent. + 1. Performance - 100, Accessibility - 100, Best practices - 100, SEO - 100 + 2. Performance - 100, Accessibility - 100, Best practices - 100, SEO - 100 + 3. Performance - 100, Accessibility - 100, Best practices - 100, SEO - 100 +- [pingdom](https://tools.pingdom.com): Testing from Asia (seemed the longest delay); performance grade MUST be B or higher and SHOULD be A. + 1. Grade A, Load time 929ms + 2. Grade A, Load time 2.04s + 3. Grade A, Load time 880ms +- [keycdn](https://tools.keycdn.com/speed) (speed test): Testing from Tokyo based on delay for pingdom; grade MUST be A. + 1. Grade A, Load time 1.05s + 2. Grade A, Load time 2.42s + 3. Grade A, Load time 937.25ms + +I released the updated code and turned OPcache on. The server default settings are different than my local defaults; therefore, I updated my local server to match those of the server. + +```bash +/usr/local/php80/bin/php -i | grep opcache +``` + +With the following changes. + +```bash +opcache.enable=1 +opcache.enable_cli=0 +opcache.memory_consumption=128 +opcache.interned_strings_buffer=8 +opcache.max_accelerated_files=10000 +opcache.revalidate_freq=2 +``` + +The `opcache.fast_shutdown=0` parameter doesn't seem to exist. I commented it out on my local server settings. + +Also added lazy loading and asynchronous image decoding to the content using the [Default Attributes](https://commonmark.thephpleague.com/2.0/extensions/default-attributes/) extension. + +```php +use League\CommonMark\Extension\CommonMark\Node\Inline\Image; + +'default_attributes' => [ + Image::class => [ + 'loading' => 'lazy', + 'decoding' => 'async' + ] +] +``` + ### November 30th, 2021 I haven't actually done a deployment, so, this will mainly be about what's happening in local development. I'm still trying to optimize as much as possible locally while not relying heavily on caching; however, I'm not sure that will work out for much longer.