3

I am developing a page for a site uses a few Javascript files. These scripts may take around a second each to download and this impacts user experience negatively on a first load. I can live with that. However, the scripts are downloaded again everytime. The browser just won't cache them.

I noticed that the HTTP response includes the cache-control header, and it's set to private,max-age=0 for my javascript files. The CSS files have this header with the same value, and so does the page itself. This basically tells the browser to always fetch these files again upon each request.

I also noticed that any files within /layouts has the same header set to max-age=31536000. I would really appreciate if I could have my JS and CSS files using this value for the cache-control header.

This is a SharePoint Online hosted solution, by the way, so I don't have access to IIS. Is there anyway I can instruct SharePoint to serve specific files, or files within a specific folder, with a custom value for the cache-control header? Site or site collection policies, extra tags on the page or master page, code-behind in a webpart... I am willing to try anything. I just have been googling for this for quite a while now and I am yet to find anyway to set that header by hand.

Edit: I set up a meta tag in the master page like this:

<meta http-equiv="Cache-control" content="public,max-age=31536000">

In Chrome dev tools I can see the tag just like that in the source code, but the http response still comes indicating a value of private, max-age=0. Am I doing something wrong?

1

So I searched some more and found an answer to this within this site.

This question is older than mine: Farm Solution Vs. SandBox. Basically, a user is asking what the differences are between the two models.

In my case, I am working with sandbox solutions. One of the answers says this about sandbox, and I quote:

No Cacheing support, you can create custom cacheing for complex HTML using a HTML field in a custom hidden list to prevent re generation

So you can cache something that comes from a list, but that's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.