Mobile app version of vmapp.org
Login or Join
Yeniel560

: "?" leading UTM codes causes longer page load time than "#" I found and fixed a problem where my utm code was drastically slowing down page loads. The problem was the leading character was

@Yeniel560

Posted in: #Html #Php #Wordpress

I found and fixed a problem where my utm code was drastically slowing down page loads. The problem was the leading character was a ?. The solution was to change it to a #. Now, we have literally hundreds of campaigns with the leading ? and manually changing them will take forever.

Is it possible to change that ? to a # as the request comes in and avoid the page load issue?

It seems like there should be some way to use Rewrite URL to do it.

If not, can anyone help with why on earth the dang question marks cause a 20 second page load while hashtag is less than 2?

For example, the following has a 15-20 second load time:


example.com/?utm_source=df_intermediate&utm_medium=email&utm_campaign=test

Whereas, the following has a 2-4 second load time:
example.com/#utm_source=df_intermediate&utm_medium=email&utm_campaign=test

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel560

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

This looks like a server-side caching issue with your site. (You perhaps need to remove the query string when generating a cache key?)

The problem is with any query string, not just UTM codes. Try appending ?hello=world to any URL and you get an extended (20+ second) load time on the initial (non-cached) request. However, request the same URL again and subsequent responses are 2+ seconds - this is with the local browser cache disabled.

By changing ? to #, you are changing the query string into a fragment identifier. The fragment identifier is not sent to the server, so does not interfere with your server-side cache.

It is perhaps possible to externally redirect from the query string'd URL to one with a fragment id, something like this in .htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(utm_source=.*)
RewriteRule (.*) /#%1 [QSD,NE,R=302,L]


This requires Apache 2.4 for the QSD flag (which strips the query string). The NE flag is required since we are rewriting to a URL with a special character (#) - to avoid it being percent encoded.

However, this is only masking an underlying problem and I would expect could cause more problems in the future.

10% popularity Vote Up Vote Down


 

@Deb1703797

I think using # instead of ? is worse.

With a standard URL, anything after # normally means a tag on the page and the tag is defined from an ID value or if you want to go old-fashioned, <a name='tagnamehere'>.

If your pages are mainly static (where the content from a URL is the same regardless of who or what accesses the URL), then you need to cache the pages on the server so that the first time the page loads, it can load slow because then the cache file is created while the page is prepared, but the second and subsequent times the page loads, it will load fast because only the cache file is read instead of all the database processing and whatever else is working the server CPU to deliver the page.

If your pages are dynamic, then try to cache all the static parts of the page. For example, if you have a page that displays everything the same except for the date and time value, then cache everything else and have the date and time value load as normal.

When you are done, use webpagetest.org to test your page to see the Time To First Byte value (TTFB). Anything above 0.2 seconds is bad.

See this URL for more of an explanation of when a # can be used in a URL:
www.boogiejack.com/html/html-anchor-tag.html

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme