Making Web Pages Display Correctly on Mobile Devices
Sometimes, when viewing a website on a mobile device, the page may display incorrectly, showing random characters, “gibberish” text, or broken formatting. This issue is usually caused by how some mobile carriers handle web traffic.
Problem
Section titled “Problem”- On certain mobile networks (e.g., AT&T, Vodafone), web pages may appear corrupted.
- If you check the page source, you may see random characters inserted into the code.
- The issue typically occurs only on cellular data connections (3G/4G/5G).
- When using Wi-Fi, the problem does not occur.
-
Some wireless providers use non-transparent proxies that modify web content in transit.
-
These proxies attempt to optimize performance by:
- Removing whitespace
- Compressing or altering code
-
Unfortunately, these automatic modifications can break existing code, causing display errors.
Resolution
Section titled “Resolution”To prevent proxies from altering your site’s content, you must instruct them not to transform your pages. This is done by setting the Cache-Control: no-transform directive.
Option 1: Set in PHP
Section titled “Option 1: Set in PHP”Add this line at the top of your PHP files:
<?phpheader("Cache-Control: no-transform");?>Option 2: Set in .htaccess
Section titled “Option 2: Set in .htaccess”If your site runs on Apache, add this to your .htaccess file:
<IfModule mod_headers.c> Header set Cache-Control "no-transform"</IfModule>