PDFs will load slowly due to various reasons. A big size will take longer to download, improper encoding will disable various loading feature. We have pointed out some of the major issues that can be resolved to make loading faster.
1. Cross Origin (CORS) #
This occurs when the file and page are in HTTP and https mixed protocol. This is a result of improper https redirection. We recommend using a proper setup to redirect every HTTP request to https to avoid any conflict.
If you are using the file from another domain, make sure you have proper CORS setup done in another domain. For Apache Server, add following lines in .htaccess file
Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers "Range" Header set Access-Control-Expose-Headers: "Accept-Ranges, Content-Encoding, Content-Length, Content-Range"
More Info: https://enable-cors.org/server.html
NOTE: PDF files from online file-sharing servers like Google Drive, One Drive, Dropbox cannot be configured for CORS access. They won’t allow it.
2. Bad End Offset #
This can occur when there is cache issue with browser and server. In such cases disabling cache is advisable.
Known occurrences with:
- nginx and Chrome browser.
- o2Switch hosting that uses LightSpeed caching.
<IfModule mod_expires.c>
ExpiresByType application/pdf "access plus 0 seconds"
</IfModule>