Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using Scripts.Render() on ASP.NET MVC - what can the reason be that 6 hours after the update users still get the old (bundled) script file?

I've updated some scripts within our TypeScript files, but users still seem to get the old versions of the bundled script. How do I know? Because I'm seeing (remote) JavaScript errors in our logs that refer to a class that 100% exists within the new latest version. It has been more then 6 hours ago and I can verify that the ?={hash} has changed.

I have the feeling the suspects are, one way or in combination any of these:

  • Static content (IIS)
  • Scripts.Render("")
  • TypeScript compilation
  • Azure

I have the feeling it's in some kind of cache or that it has to do with static content serving. Or with the Script.Render().

What can the reason be? It drives me crazy, because I know the site is broken for some users, but I can't get a fix out.

I've included the headers below.

headers

This is the code for the bundle. Note that core.js is being generated by TypeScript.

{
    var bundle = new Bundle("~/scripts/main-bundle");
    bundle.IncludeDirectory("~/scripts/fork", "*.js", searchSubdirectories : true );
    bundle.IncludeDirectory("~/scripts/app", "*.js", searchSubdirectories : true );
    bundle.Include("~/scripts/bundles/core.js");
    bundles.Add( bundle );
}

Update

If they are getting the old HTML because it might be cached, so the hashbomb doesn’t change - shouldn’t they still have a consistent pair of JS and HTML?

like image 511
Dirk Boer Avatar asked May 17 '18 23:05

Dirk Boer


People also ask

What does scripts render do?

Render generates multiple script tags for each item in the bundle EnableOptimizations is set to false. When optimizations are enabled, Render generates a single script tag to a version-stamped URL which represents the entire bundle.

How can you include scripts in an MVC application?

Go to Views -> Shared -> _Layout. cshtml file and add the render code. Make sure to register the custom javascript file after the jquery bundle since we are going to use jquery inside our js file. Otherwise we will get a jquery error and also register this before the script RenderSection.


2 Answers

https://poules.com/us doesn't have a cache-control:max-age specified so you probably have some users on browser cached html which would use the old scripts.

There is a s-maxage set, but that is only an override for public cache max-age which isn't set and this page cache is set to private; so I don't think it is doing anything.

Also, you can check Azure to see what is deployed if you have access to the Azure portal.

like image 138
ATerry Avatar answered Nov 16 '22 00:11

ATerry


best way i find around any web interface that requires a forcing of update client is to use a manifest file, and have that specify the scripts. Your bundle needs to then update the manifest with the correct hash. I normally just use a grunt task for this and placeholders within the manifest.

You then manage the manifest in code. with listeners for updateReady and completed so you know when to refresh the browser.

On another note, Application Cache is for older browsers, for new browsers you have to use the Service worker in order to provide a facility to update your app.

With both applied you will have a release schedule you can manage and mitigate issues like you have been getting at the moment.

Another method if you have an API, is to allow the API to serve up Javascript, based on a given version number for the users current web front end. This way you can then inform the users that a more recent version is up to date, and offer a reload button.

However Application cache through manifest or service workers, is more accessible to other teams, if you have a split, front end and backend setup.

+++++++++++++++++++++

Another reason why, could be because your web font is blocked by ad blockers like Ghostery and AdGuard. This in turn creates a unhandled error

auth-dialog-window?openerOrigin=https%3a%2f%2fpoules.com&color=FF533C&pool=&openerType=iframe:82 Uncaught ReferenceError: WebFont is not defined
at auth-dialog-window?openerOrigin=https%3a%2f%2fpoules.com&color=FF533C&pool=&openerType=iframe:82

This could potentially stop other things from working and loading in the right way. You need to make sure that you are picking up and catching all errors and events for all of the users, no matter what plugins they use.

To be fair, on looking it could very well be the adBlockers that are your main issue here.

Anyway hope this all helps

like image 28
davethecoder Avatar answered Nov 15 '22 23:11

davethecoder