HTML not updating? - javascript

I have a CGI application written in C. When I POST (delete data) to the cgi app from the html form, the action is correctly executed on the server but the page does not refresh after the POST. It does flicker, but displays the non-updated page. I then have to hit the browsers refresh to see the correct updated html page (showing data has been removed).
Is this the web server? Javascript? or just a browser setting? (I am using GoAhead web server, cgi app in C, javascript, html and Fire Fox.)
Any help is appreciated.

It's your browser cache that is playing tricks on you.
Check the HTTP headers you get when GETting (or POSTing) the page to see if there are anything about cache, if there is it's your webserver that is causing the cache otherwise it's the browser. Try with a different browser, or make the webserver send the page with a negative expiration date.

Are you sure you're returning an updated page in response to the POST?

In order to be sure what is happening, you need to sniff the local network (using Wireshark).
Wrieshark shows you the traffic and also can filter a specific stream.
After you capture you can understand what exactly was sent to the server and what was the respond.

If you are using Firefox you need to install the Firebug plugin and it will show you if your pages are being cached or being retrieved from the server correctly in the "net" panel.

Related

How to post back to server after Single Page Application release/update

I have a SPA Angular website. Whenever we release a change to the website, the user's browser does not go back to the server to get the new javascript files. The app happily keeps running in the user's browser, and while it will make ajax calls for data, the javascript files do not change. This can cause errors if the signature of the back-end API being called changes, etc. If the user refreshes the page, they get the updated javascript files and everything works fine after that.
Is there a way to tell the browser that the site has been updated and to get the new javascript files, rather than just running the app with the same files?
I use the Angular CLI to build the application, so when the website is released, the javascript files have hashes at the end etc. This isn't an issue with files being cached and not updated... it's an issue with the browser knowing that it needs to request the files or refresh the page.
You could use web workers to poll the server for changes and refresh the browser when changes are found.
An alternative to web workers is using setInteterval just refresh after a given time.
Yet another alternative is to have a version number in your API responses, and the JavaScript handlers would refresh the page when the version numbers are out of sync.
You could write a program in your angular code that:
periodically checks the version of the api if changes where made
does the periodic check to ascertain when the user is idle AND when the user is not in a edit page with dirty fields.
refreshes the page when step 2 condition is met
use this library to watch idleness
https://github.com/shawnmclean/Idle.js
If the file udated have the seame name add this text after the "?" like "?ver1.1" is suppose to tell the browser that there is a new version of the file.
you can use manifest file
https://html.spec.whatwg.org/multipage/offline.html#manifests
another way is with
CacheStorage,clear()

ag-grid - Refresh on Page Load

I'm using the JavaScript version of ag-grid to display data on my page. When I update data on a different page and come back to this one, it still shows the cached data from before. If I hit ctrl+F5 it will then refresh. Is there a way to either get it to not cache anything or to refresh on page load? Seems like a simple setting that I'm not seeing.
Update: So I'm not sure if it has anything to do with the cache. It seems like it will refresh that data under circumstances. If I have the dev tools open (Internet Explorer 11), then it will refresh the data with no problem. Seems like a strange thing, not sure if it's browser related or not.
Update 2: It's turns out that it wasn't ag-grid but the way I was querying the data. If you are using jQuery.ajax make sure the cache is setup properly ><.
What caching (HTTP) headers is your data source returning?
You want it to be returning certain headers that tell the browser that the response should not be cached.
For example: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Examples
Look up how to set caching settings with your web server, etc.

PHP Initiator in IE

I have a web page which will load an external javascript processed by PHP. In Chrome and Firefox if I want to get the initiator of the js file through PHP, I just need to get it by the superglobal variable $_SERVER["HTTP_REFERER"]. However, this would not work in IE if I visited another web page before browsing this web page. How can I get the initiator web page even in IE?
PHP is not processing JavaScript. Your Browser is processing JavaScript.
The HTTP headers are known to be unreliable, everyone can change their fields to whatever you want in the request. You cannot fix your problem by using $_SERVER["HTTP_REFERER"] nor anything in JavaScript related. Some browsers have turned off the refererrer or offer the possibility to turn it off, as some add-ons will also remove the referrer.
The only reliable way is to generate security tokens, which you will use only once per JavaScript call. Save it in a session, compare them when calling the html/php and when calling the js/php.

Force reload all page resources, not from cache

I would like to do something similiar to opening the developer tools in chrome and checking disable cache and then reload the page.
I can't modify the urls in any way (eg. appending a timestamp in the query) as this will work once, but next time I reload the page normally, the resources will load from the old url without the timestamp and be the old cached version.
I only need support for chrome and I don't have access to the server.
Basically I need the resource files to be update in the chrome cache, without altering the url.
referring from this topic: Prevent browser caching of jQuery AJAX call result
As you are able to editing the server-side script to setting no cache header, it is hard to handler it perfectly on IE. The only way can do for client side is unfortunately adding timestamp on end of the query string.
In Chrome reloading all page resources regardless cache can be forced by long pressing Refresh button while developer tools is open

Versioning Javascript Files to Prevent Unnecessary Cache Clearing

I version all of my client side JS files like "/js/myfile.js?v=3903948" so that my clients don't need to clear their browser cache to ensure they get the updated files. But every time I push an update, without fail, at least one person runs into a problem where they are running the old version and get some kind of error. I used to think that this was just them having already been on the page during the release and just needing to reload the browser, but this happened to me today when I was definitely not previously on the page. I browsed to the live site and was running the old code. I needed to do a browser refresh on that page to get the new file.
What can cause this?
PS I was using Chrome on Win7, but I have seen clients report this before on all different browsers.
If your main web page can also be cached, then the old version of that page can be requesting the old version of the JS file. JS file versioning works best if the page that actually refers to the JS file cannot be cached or has very short caching time.
I agree with jfriend00 about the webpage itself being cashed and thus requesting the old javascript version.
To prevent this, you can have the javascript file loaded by an ajax (Post) request, either requesting the server what is the accurate(latest) version number to download, or requesting the javascript itself and inserting it, e.g. in the head of the page.
Edit: see for example here
I make a quick AJAX request to the server for the version it expects them to have, then force them to refresh the page if the client's script is old.
Seems that proxy or some load balancer is serving old content instead of new. Also check IIS/webserver settings how are these files cached/expired.
You can check what is going on on the wire with tools like Fiddler.

Categories