Caching of old files

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
9/11/2021 5:05:36 PM
Total Posts 53

Caching of old files

Hi all

We use mojoportal for our intranet and upload new versions of files with the same filename so we don't have to update hyperlinks across the intranet.

However if the user has downloaded the document previously, it remains cached and the new version will not download until you right click on the document and select refresh. This is not ideal but a workaround for PDF's.

I understand this is a browser issue but is there any code I can put into the master template to force the browser not to cache documents? Alternatively, is there a similar setting to force caching based on age?

Thank you, Sandy

9/13/2021 9:32:46 AM
Total Posts 2247

Re: Caching of old files

Hi Sandy,

You can use UrlRewrite to change the cache-control header for specific file types.  Merge the following into your web.config file after the httpErrors section of system.webServer. You'll want to add additional file types in the preCondition section. If your web server doesn't have the url rewrite module, you'll need to add it.

        <rule name="RewriteCacheControlForSpecificFileTypes" preCondition="NoCacheFileTypes">
            <match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
            <action type="Rewrite" value="max-age=0,no-store" />
            <preCondition name="NoCacheFileTypes" logicalGrouping="MatchAny">
                <add input="{REQUEST_FILENAME}" pattern="\.pdf$" />
                <add input="{REQUEST_FILENAME}" pattern="\.docx$" />

The max-age=0 value will clear the browser's existing cache for these file types and the no-store value will prevent the browser from caching these file types again.


Hope this helps,


9/13/2021 6:53:20 PM
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Caching of old files

If you want to keep the caching optimization, but address it on a case-by-case basis, a relatively simple method we use to get around this is to update the URL pointing to the updated file, and add a "fake" small query string to the end. This makes the browser see the updated URL as different than its cached version, and it will download the file again.

For instance, if the old link was

When the MyPDF.pdf  file is updated, you can change the URL to something like:

The "v=2" query string doesn't do anything but ensure all browsers will pick up the new file regardless of cache status.

1/5/2022 11:10:16 PM
Total Posts 53

Re: Caching of old files

Hi Joe

I tried copying and pasting the rewrite code but I am getting a 500 - Internal Server Error. It looks like our web server needs the URL Rewriter module.

Hi Jamie

Thanks for your method, we can try to do this in the meantime.

Apologies in getting back to you both but thank you for responding and your advice.

Kind regards, Sandy

You must sign in to post in the forums. This thread is closed to new posts.