We are running into issue where our clients are served stale js, css files after code is deployed. We are using IIS as our webserver and our code is in ASP.Net 4.5. I did some research and figured out that ETag in conjunction with Cache-control should work. As I understand ETag is automatically generated by web server based on datetime stamp of file so I ran following steps to see why the system is not sending the latest version of js and css files.
Navigated to my website to a webpage let's call is demo.aspx.(Now assuming that demo.aspx contains reference to a.js, b.js and c.css)
Verified that a.js, b.js and c.css file were requested by browser and webserver delivered those files after I hard refersh a page(Ctrl + F5) on my website.
Clicked on some other webpage
Went to webserve and manually updated files (a.js, b.js and c.css to update datetime stamp of those files)
Navigated to demo.aspx again.
This time I see only request made to demo.aspx but not to any of the resource file (a.js, b.js and c.css).
I am at loss as to why .js files are not requested when I access my demo.aspx page.
Also, Is there any easy way to force client browsers to download latest version of .js and .css files every time I deploy code. Based on my research, I did find out that one way to do would be to rename .js and .css file. Please note that this soution won't work for us.
We do use update panel in our projects. Not sure if that has anything to do with browser not requesting js files second time
A widely used trick is to add a query string parameter that is incremented with every new version of the css or js file.
Like myScript.js?version=12. When the the number changes the browser sees it as a new file and it's downloaded rather than retrieved from cache.
Just changing the timestamp by editing the file won't work, the browser does not get the timestamp from the server. You can try this by saving an image or file from the website, they all have the timestamp of when they were being downloaded.
Related
I'm using FastAPI and the Uvicorn server to build a website, but when I make changes to the CSS files and reload the webpage it doesn't pick up these changes.
In fact, even when I switch off the server and reload it, Uvicorn still doesn't pick up the changes to the CSS file.
Previously, the server picked up the changes fine, what's caused this to change?
The issue is not with Uvicorn, but with your web browser stashing 'static' files in its cache.
FastAPI uses a method that designates a directory the 'static folder'. This tells the server that the files in this directory should remain constant and don't need to be downloaded every time a webpage is loaded.
Check inside your app's main module and look for the following piece of code:
app.mount(
"/your_static_file_web_path",
StaticFiles(directory="your_static_directory"),
name="your_name_for_static_app"
)
This function creates a second FastAPI app within your pre-existing one that handles all of your static files. The second argument defines your static file directory. Anything within that directory will eventually be cached by your web browser and further changes will not be loaded. This prevents your page from loading the updated CSS.
As noted in a comment above, if you want to work around this issue, you can hold shift and reload the web page - this is known as a hard refresh. A hard refresh will force your browser to re-download everything, including static files.
I am in the process of adding a Content Security Policy for a laravel application. While downloading external css and font styles to the local assets I have run into some odd template behavior.
I wanted to test that the paths to the newly downloaded libraries were correct, but when I change the name of files I downloaded and refresh, even with the browser cache disabled, it is still referencing the old location successfully. If you try to access the file in the old location directly by file path it fails (because it no longer exists).
Even more strangely, if I pull the code down to another computer and run it (I have not added the new libraries to git yet), the page still seems to think it correctly loaded that resource.
I tried clearing the following directories:
storage/framework/cache
storage/framework/sessions
storage/framework/views
and running the code again - on multiple computers, and it still reports that it is loading these files that are no longer there?
Does Laravel or commonly used front end frameworks with it store compiled templates somewhere else? I am completely perplexed...
Here's what I would like to accomplish:
I have a file stored in Windows Azure Blob Storage (or for that matter any file which is not on my web server but accessible via a URL).
I want to force download a file without actually downloading the file on my web server first i.e. browser should automatically fetch the file from this external URL and prompts the user to download it.
Possible Solutions Explored:
Here's what I have explored so far (and why they won't work):
Using something like FileContentResult as described here Returning a file to View/Download in ASP.NET MVC to download the file. This solution would require me to fetch the contents on my server and then stream from my server to the browser. For this reason this solution won't work.
Using HTML 5 download attribute: HTML 5 download attribute would have worked perfectly fine however the problem is that while it is really a very neat solution, it is not supported in all browsers.
Changing the file's content type: Another thing I could do (at least for the files that I own) to change the content type property of the file to something that the browser wouldn't understand and thus would be forced to download the file. This might work in some browsers however not in all as IE is smart enough to go beyond the content type and sees the file's content to determine the content type. Furthermore if I don't own the files, then I won't have access to changing the content type of the file.
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file.
Is this something which can be accomplished? If yes, then any ideas how I could accomplish this?
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file [without exposing the URL of the file to the client].
You can't. If the final URL is to remain hidden, your server must serve the data, so your server must download the file from the URL.
Your client can't download a file it can't get the URL to.
You can create file transfer WCF service (REST) which will stream your content from blob storage or from other sources through your file managers to client browser directly by URL.
https://{service}/FileTransfer/DownloadFile/{id, synonym, filename etc}
Blob path won't be exposed, web application will be free from file transfer issues.
consider my file
Test.mxml
output file
Test.swf
Each time i make some changes in Test.mxml corresoping swf file is generated.
But this is causing some problem in proxy server.
When i change the version of swf file generated its working fine(im able to see new changes as proxy server will load the new renamed file)(i tried versioning)
I cant see my changed swf file, its giving me cached swf file because of which the changes are not reflected.
A few approaches to handle this:
It may be possible to tell your proxy not to cache this file if you have any control over it.
Sometimes people use the "Random number" technique to prevent files from being cached. that is, in your HTML page that wraps your SWF; add a random number to the SWF location. Conceptually like this myswf.swf?someRandomNumber .
Every time you deploy a new build you could change the filename.
You can also try having your browser send the no-cache headers, which causes the (WebSphere Edge) proxy server to dump its cached copy too. In Firefox, at least, Shift-Reload does this. I think that's true in IE and maybe Chrome too.
I have used a external js file for a upload operation in my page.. once the file get loaded in temporary folder, it gets loaded from there even if new changes are made the old version that exist in temp folder gets loaded... i have written
Response.Cache.SetCacheability(HttpCacheability.NoCache);
on my page But it still loads the js file in cache. When i cleared the temporary files manually it works fine...But i cannot ask my client to clear temp folder,,,
Is there any solution to load js file not from the cache, ie reload every time page is loaded...
Setting cache headers on page will control caching of page output - it won't affect other files such as js files. But I would rather prefer js file to be cached so why you want to do otherwise is not clear. If its for development purposes then you can always hit browser refresh button to get fresh java-script file.
If you want to do it in production environment then you can append some random query parameter after the js file url (.../file.js?q=4563888). You can use Environment.TickCount etc for generating the random number.
I'm assuming this is just for your while your developing, if frequent changes are made in production this wont help your users.
Most browsers allow you to ctrl+F5 to reload all content from a page rather than just a standard refresh of the page which loads images,css, js etc from cache.