Lately I’ve been tinkering around with my blog to see if I could get a better score in Google Web Vitals. The “Avoid Excessive DOM Size” attracted my attention. The details showed that my code fields were to blame. I use Google Prettify as it is lightweight and does a pretty good job, but… it renders way too much span elements. Let’s see if we can make it spit out less.
Twitter uses its url shortener to place photo’s in Tweets. I’ve tried processing these URLs in the browser, but cross site scripting measures prevented me from processing the result with jQuery.
I decided to resolve it in C# (as I’m using ASP.Net). The following script leverages a WebClient and a regular expression to extract the photo URL from the shortened URL. This code could be added to a handler or a webservice that can be called from script.
PowerShell is very similar to .NET, so it is no surprise that it is very popular with .NET developers. It is a language for writing scripts, so you might encounter some unexpected situations. I had this experience when I tried to parse some HTML with PowerShell: I could not get the replacement with regular expression groups to work! It turned out that my .NET knowledge was working against me…