Posts

Showing posts from October, 2023

Reduce the impact of third-party code - Google Tag Manager - Analytics

Image
In this post, I describe how to reduce the impact of third-pary code such as Google Tag Manager (gtag) and Google Analytics. This can lead to a longer Largest Contentful Paint (LCP) which can cause Google Search Console Core Web Vitals to report "LCP issue: longer than 2.5s" and URLs as either "poor" or "need improvement". Cause The "reduce the impact of third-pary code" message can appear when you run PageSpeed Insights or Lighthouse within Google Chrome on a page which includes the Google Tag (gtag.js).  I found that my performance score would still be negatively impacted even if I used async or defer in the script tag which loaded the Google Tag. I tested removing the Google Tag completely and my score improved to 100 so I knew the Google Tag was the cause. Resolution To resolve the issue, I set a timeout then loaded the Google Tag Manager after the timeout, in this case 3,000 milliseconds later: window.setTimeout(function () { ( function (w,

link tag preload image media attribute min-width not working

Image
In this post, I describe how to fix an issue I had getting the link tag media attribute with min-width to work correctly. Cause Despite specifying a min-width of 500px, the link tag was still preloading the image even below a screen width of 500px.  The cause of the problem turned out to be the placement of my link tag in my HTML. Resolution The resolution turned out to be very simple.  I had inadvertently placed the link tag above my viewport meta tag: < meta name ="viewport" content ="width=device-width, initial-scale=1.0" /> To resolve the issue, I moved my link tag below my viewport meta tag:     < meta name ="viewport" content ="width=device-width, initial-scale=1.0" />         < link rel ="preload"           href ="bg-image-wide.png"           as ="image"           media ="(min-width: 500px)" />

Too many characters in character literal - defer CSS - ASP.NET

Image
In this post, I describe how to defer non-critical CSS in ASP.NET without getting the error: Too many characters in character literal Cause This error can occur when you copy the suggested code from this  defer non-critical CSS page into an ASP.NET page. < link rel ="preload" href ="styles.css" as ="style" onload =" this.onload=null;this.rel='stylesheet' "> < noscript >< link rel ="stylesheet" href ="styles.css"></ noscript > Resolution I used a script tag to load the CSS instead of a link tag:      < script >         var link = document.createElement( "link" );         link.rel = "stylesheet" ;         link.href = "/css/font-awesome.css" ;         document.head.appendChild(link);     </ script > You may also wish to add a noscript tag just in case scripts are disabled:      < noscript >         < link rel ="s

IIS .webp file - add a MIME Type - HTTP error 404.3

Image
In this post, I describe how to add support for a .webp file in IIS and ASP.NET to fix the error: "HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map." Cause This error occurs because I'm trying to access an image in WebP format on a site in IIS or ASP.NET which does not have the .webp MIME type added. Resolution ASP.NET To resolve the error in ASP.NET, add the following to web.config:          < system.webServer >              < staticContent >                                   < mimeMap   fileExtension =".webp"   mimeType ="image/webp"   />              </ staticContent >          </ system.webServer > IIS To resolve the error in IIS Manager: - Open IIS - Go to your site then double click MIME Types : - Press Add...  under Actions in the top right: - Enter .webp as the F

HTTP error 413 - get and set uploadReadAheadSize in IIS

Image
In this post, I describe how to get and set uploadReadAheadSize in IIS to fix the error: "An unknown error occurred while processing the request on the server. The status code returned from the server was: 413" Cause This error occurred after I created a self-signed SSL certificate and tried to access a site in IIS over HTTPS. Error code 413 means "Request Entity Too Large". Resolution To resolve the issue, I increased the uploadReadAheadSize in IIS as follows: - Open IIS - Select your site in the treeview on the left - Open Configuration Editor : - Open the Section drop down, expand system.webServer then select serverRuntime : - Here you can check your current uploadReadAheadSize and set a new value in bytes between 0 and 2147483647 ( more information from Microsoft ) - Click outside uploadReadAheadSize then press Apply in the top right to save your changes Error 413 should now be resolved. Related Posts - NET::ERR_CERT_WEAK_SIGNATURE_ALGORITHM - IIS SSL Certifi

NET::ERR_CERT_WEAK_SIGNATURE_ALGORITHM - IIS SSL Certificate

Image
In this post, I descibe how to fix the error: NET::ERR_CERT_WEAK_SIGNATURE_ALGORITHM which can occur after you create a self-signed SSL certificate for an HTTPS binding in an IIS web site when you try to access that site in a modern browser such as Chrome or Edge: This is a follow up to my previous post: Mismatched Address certificate error - HTTPS localhost IIS Cause If you followed the steps in my previous post, the certificate is created with the certificate signature algorithm PKCS #1 SHA-1 With RSA Encryption : In 2017, SHA-1 was proven insecure and thus Chrome and Edge flag it as not secure. Resolution The New-SelfSignedCertificate cmdlet includes a HashAlgorithm parameter which can be set to SHA-256 .  This can easily be added to the PowerShell script from my previous post as follows:  $rootcertname = "ROOT" $certname = "localhost"   # Create the root certificate $rootcert = New-SelfSignedCertificate `                 -Type "Custom&q

Windows sound not working - can't hear audio - can't play audio

Image
In this post, I describe two ways to fix an issue with Windows sound whereby either audio cannot be played or audio is playing but cannot be heard. Issue This issue occurs in both Windows 10 and Windows 11.  When it occurs, I either cannot play audio or, when I do play audio, the sound cannot be heard. There are two resolutions: Resolution 1 One way I have fixed this issue is by restarting the Windows Audio service: 1. Open Services (search for "services" in the Start menu) 2. Click in the right hand panel and press W to skip down to the services that start with W 3. Right click Windows Audio then select Restart My playing audio was now audible. Resolution 2 If the sound icon in the taskbar has a red cross next to it: Either follow the steps above and, if the Windows Audio service is stopped, start it Or, try right clicking the sound icon in the taskbar and selecting Troubleshoot sound problems . If the Windows Audio service won't start and Troubleshoot sound problems d

How to create a self-signed public certificate - Powershell

Image
In this post, I describe how to create a self-signed public certificate using Powershell. Resolution To create a self-signed public certificate in the current user's certificate store, in a PowerShell prompt, enter the following (changing the certificate name as required): $certname = "SelfSignedCertificate" $cert = New-SelfSignedCertificate -Subject "CN= $certname " -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature -KeyLength 2048 -KeyAlgorithm RSA -HashAlgorithm SHA256 The certificate should now be visible in the Certificates MMC. Export To export the self-signed public certificate in .cer format using the $cert variable from the previous command, enter the following (changing the file path as required): Export-Certificate -Cert $cert -FilePath "C:\Users\sysadmin\Desktop\ $certname .cer" This post was based on information from this Microsoft page: - Create a self-signed public