How to disable cache on chrome for Android? - google-chrome

How to disable cache on chrome for Android?
I change my page content, and refresh the page, but the content still is old.
I have set the nginx config like below, but it has no effect.
#disable cache
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma no-cache;
add_header Expires 0;
Is there a way to get my newest page without manually clear cache again and again?

This may not be the easiest way, but it will 100% work and should be part of your development setup anyway.
Using Google Chromes web tools on Windows or Mac will allow you to do "remote debugging".
Enable remote debugging on Android device through Developer Menu in settings.
Connect phone to PC using USB
Open Google Chrome and access the developer console (F12)
Click on the three dots (top right) > more tools > Remote devices.
Scroll down to select your mobile device, at this stage you should see all chrome instances open on your phone. Select the instance you wish to "force reload and disable cache" by pressing Inspect
Another screen should appear allowing you to access the network tab and select "Disable Cache"

Currently there is no way to disable cache on chrome for Android but it is possible to clear the cache.
UPDATE: As of now there is a way to disable cache with requires your phone to be connected and needs remote debugging, please refer to Dean Meehan's answer for more info
Follow these steps to clear the cache.
http://www.refreshyourcache.com/en/chrome-android/
Click on the menu button (three dots in the topright corner).
Click on Settings in the menu.
Click on Privacy in the menu.
Click on Clear browsing data... at the bottom.
Select Empty the cache from the list.
Confirm clear browsing data.

I know the question is asking about disabling cache on chrome for Android, but this may help people looking for a solution to mobile development.
To see changes on your website with your Android device use the New incognito tab in chrome web menu.
Click top right drop down menu in chrome browser
Click "New incognito tab"
Navigate to your website and see all your most recent changes.
IMPORTANT: To see new changes after viewing with incognito, you must close the incognito mode completely and reopen due to the current tab also caching.

To disable the cache first you'll have to disable scripts / css caching on the ones you are editing.
In order to do that, add a timestamp to your file inclusions :
<link rel='stylesheet' href='/static/css/main.css?t={{ts}}'/>
<script type='text/javascript' src='/static/scripts/main.js?t={{ts}}'></script>
{{ts}} being a timestamp (I'm using jinja templating).
Then if you edit your html page, you could change the request adding a random parameter to it as such :
test 1 :
mywebsite.com/this_page
test 2 :
mywebsite.com/this_page/?i=1
test 3 :
mywebsite.com/this_page/?i=2
...
It's more a hack than a real solution, but chrome kindly ignores the cache-control meta, so there aren't lots of clean way to do it.

The following bash script will rename
<script src="path/to/app.js"></script>
to
<script src="path/to/app.js?t=18:15:45></script>
in an index.html file, which will prevent mobile caching.
#!/bin/bash
time=$(date +"%T")
sed -i "s/app.js/app.js?t=${time}/" ./path/to/index.html

Download this app : App Cache Cleaner
Open the app
Go to the app settings via the '3 dotted' button
screenshot
Tick mark the option to show widgets and the rest is upto you
You may as well disable Chrome's Data Compression policy and preloading of pages.
As of now, there are no 'disable cache' option in chrome
screenshot2
PS:i cud not show pictures because of my low rep, help me increase that too ;p

Related

Can't find the "Override requests with workspace project" in Chrome DevTools Canary

For the life of me I can't find where to enable this setting: Override requests with workspace project in Chrome Canary v64.0.3
Where do you enable this feature?
I learned about this feature from here: https://umaar.com/dev-tips/162-network-overrides/
Currently with 65 Chrome Canary it's not experimental anymore.
But you still cannot "Save for overrides" XHR requests.
This restriction is only in UI. To get XHR request override:
Open "Sources tab" in Chrome Canary DevTools and "Overrides" sub-tab under it.
Check "Enable Local Overrides" and add a folder to store changes in the filesystem.
Open "Network" tab in Chrome Canary DevTools and select XHR request
Press "Open in new tab"
Go to new opened tab Chrome DevTools - "Network"
Select the first request in the list and "Save for Overrides" button appears.
You can follow the gif from question starting step 5:
It's behind an experiment (https://developers.google.com/web/tools/chrome-devtools/ui#experiments) then it'll be under experiments in the settings panel of devtools.
Please do be warned though, this is an experimental feature, there are bugs and it might not work as intended.
We are trying hard to get it fully released soon (on Canary) but it needs to be a 1st class feature before we will feel ready to release it.
I think they might have shipped the feature, so it's no longer behind an experiment.
Try the workflow that Umaar outlined, omitting the step about enabling the experiment.
Haven't tried it myself yet, so I could be wrong
The feature is no longer an experiment in Chrome Canary (current version at the time of this: 64.0.3261.0). You can start to use it now. It will take a little time to arrive in Chrome stable.
In the latest version of Chrome Canary (Version 65.0.3317.2) you still need to enable dev tool experiments. The option is still behind the experiment flag #kayce-basques . I also followed the tutorial of Umaar - also using GitHub for testing - but I don't get any visible website changes after pressing F5.
Has someone figured out how to get it to work?
(1) Select the Overrides Tab in the Sources Panel.
(2) Click the Setup Overrides ( + icon) to add an empty folder.
(3) Confirm that Enable Network Overrides are enabled.
(4) Select the js file to be persisted on the Network Tab and display the source code in the code editor.
(5) Add code “console.log (‘hello world’);” to the beginning of the source code.
(6) Right click on the source code, select command [Save for overrides] on the context menu.
(7) Reload the current page after saving the file.
(8) Open the Console Panel and check the result.
This feature is now enabled in chrome stable you can follow these step:
In chrome go to "Sources tab" then in devtools "Overrides" click "Enable Local Overrides" then create a folder to put the changes in the filesystem. Go to
"Network" then select XHR request then "Open in new tab" then go to new opened tab Chrome DevTools - "Network"
pick the first request in the list and normally you will have a "Save for Overrides" button appears.

How can I force a hard reload in Chrome for Android

In Chrome for desktop I have options in the dev tools to disable cache completely when dev tools are opened and I have the options to manually do a hard reload when long clicking on the reload button (with dev tools open).
Is there any such technique for Chrome for Android? I didn't find any setting.
What can I do when I want to force the browser to download some javascript or css file instead of using a cached one when developing?
I'm using window.location.reload(true) according to MDN (and this similar question) it forces page to reload from server.
You can execute this code in the browser by typing javascript:location.reload(true) in the address bar.
Viewing the page in incognito mode will disable the cache. It was the only way I could force a refresh on a stylesheet without manually clearing the cache through the settings.
Also an option:
Menu
Settings
Privacy
Clear Browsing Data
Check "Cache" and press "CLEAR"
and then reload the page.
You can use the Request Desktop Site option from the app menu (to the right of the address bar) which will force the page to reload.
Simply tap it, wait for the refresh, then deselect it.
Mentioning this because you mentioned "when developing".
You can control the mobile device via your Chrome Desktop Browser.
Visit chrome://inspect/#devices on your desktop. And Inspect the device that's connected to your desktop. Agree when asked for permission.
You should now see a full fledged Devtool window for the current page on mobile device.
Now, Use the hard reload shortcut (Cmd+Shift+R) on desktop to do hard reload on mobile device!
How to reset all data for a given URL / Website on Chrome Mobile for android:
1 - Open the Chrome menu, and tap on the "i (info)" icon
2 - tap "Site settings"
3 - Tap the trashcan icon
That's it, even the most deeply ensconsed service worker for that URL will now die.
Don't forget to make sure that the "Reduce data usage" setting is turned OFF, as it seems to download cached data (from Google servers?) even though your local cache is flushed.
I know this is an old question, but I found that the accepted answer didn't work for me.
An alternate solution would be to append the url with a new url parameter
such as website.com?a=1, website.com?a=2, etc.
If you have parameters already, of course, you would use an ampersand
i.e. website.com?q=test&a=1
As of 2018, from google help center (tested on Chrome 63) :
tap on the three dots menu ;
choose History > Clear browsing data ;
if needed, choose the time period (above the checklist) ;
uncheck all items but Cached images and files ;
proceed with Clear data and confirm.
As mentioned in another answer, incognito tabs are also of great use for development.
I found a solution that works, but it's ugly.
Connect the Android device to your PC with a USB cable and open Chrome on your desktop.
Right-click anywhere on a page and select "Inspect".
Click the three-dot menu and select "Remote devices" under the "More tools" menu:
In the panel that opens, select your device and then the "Inspect" button next to the name of the tab on your phone that needs to be refreshed:
In the window that opens, click the "Network" tab and check the "Disable cache" checkbox:
Reload the page on your phone or using the reload button in the DevTools window.
Note: if your phone doesn't appear in the device list:
make sure the USB connection is using File Transfer mode and isn't simply charging
try restarting ADB or run adb devices to see if the device is being detected
The only reliable way I've found that doesn't require plugging the phone in to a PC is as follows:
1. Force stop the Chrome app.
This must be done first, and you cannot re-open Chrome until you finish these steps. There are several ways to force stop. Most home launchers will let you get to "App info" by holding down your finger on the chrome icon and selecting an "i" icon. Alternately, you may be able to go to Android settings and simply search for "Chrome".
Once in "App info", select "Force stop" as shown below:
2. Clear Chrome's cache
Select "Storage" from the same screen:
Finally, select "Clear cache".
When you return to the Chrome app, the page should reload itself and serve a non-cached version.
Additionally, I found a site that makes it easy to test if you've cleared your cache: https://refreshyourcache.com/en/cache-test/
I am in no way affiliated with it. Note that the method to clear the cache mentioned on that site is in fact outdated and no longer valid.
Keyboard shortcuts such as Ctrl+Shift+R work on Android too, you just need a keyboard capable of sending these keys. I used Hacker's Keyboard
to send Ctrl+Shift+R, which did a hard reload on my phone.
Recent versions of Chrome cache very aggressively. Even cache-busting techniques such as "http://url?updated=datecode" stopped working. You must clear the cache or launch an incognito window every time (and make sure data-saver is off).
Remote Debugging allows you to use the desktop dev-tools:
https://developers.google.com/chrome-developer-tools/docs/remote-debugging
If its just the matter of included files, just add version after the path (?v=12345678)
<link rel="stylesheet" type="text/css" href="style.css?v=12345678" />
Whoever loads the page again will see changes.
Most of the answers were not working for me.
Here is a super simple working on my Galaxy S8 in august 2020:
Add "view-source:" just before your http:.... address, navigate trough there to the changed file if different than the html or index.
You will see the unchanged file. Refresh.
Done.
EDIT: This method has been deprecated in Google Chrome and will no longer work.
ORIGINAL ANSWER:
I was able to clear the cache (including subsequent xhr) using chrome://net-internals
Then click the little arrow in the top right
Select "clear cache" from that menu.
Here is another simple solution that may work when others fail:
Today, a fairly simple developer-side solution worked for me when the caching problem was a cached CSS file. In short: Create a temporary html file copy and browse to it to update the CSS cache.
This trick can refresh the CSS file, at least in Android's blue-globe-iconed default browser (but quite likely its twin, the official Chrome browser, too, and whatever other browsers we encounter on "smart"phones with their trend of aggressive caching).
Details:
At first I tried some of the fairly simple solutions shared here, but without success (for example clearing the recent history of the specific site, but not months and months of it). My latest CSS would however not be applied apon refresh. And that even though I had already employed the version-number-trick in the CSS file-call in the head section of the html which had helped me avoid these pesky aggressive cachings in the past. (example: link rel="stylesheet" href="style.css?v=001" where you upgrade this pseudo-version number every time you make a change to a CSS file, e.g. 001, 002, 003, 004... (should be done in every html file of the site))
This time (August 2019) the CSS file version number update no longer sufficed, nor did some of the simpler measures mentioned here work for me, or I couldn't even find access to some of them (on a borrowed android phone).
In the end I tried something relatively simple that finally solved the problem:
I made a copy of the site's index.html file giving it a different name (indexcopy.html), uploaded it, browsed to it on the Android device, then browsed back to the original page, refreshed it (with the refresh button left of the address bar), and voilà: This time the refresh of index.html finally worked.
Explanation: The latest CSS file version was now finally applied on Android when refreshing the html page in question because the cached copy of the CSS file had now been updated when the CSS file was called from a differently named temporary html page that did not exist anywhere in the browser history and that I could delete again afterwards. The aggressive caching apparently ignored the CSS URL and went instead by the HTML URL, even though it was the CSS file that needed to be updated in the cache.
Adding a parameter to url fool browser to load a new page. I wrote a fuction for that purpose:
function forceReload(){
function setUrlParams(url, key, value) {
url = url.split('?');
usp = new URLSearchParams(url[1]);
usp.set(key, value);
url[1] = usp.toString();
return url.join('?');
}
window.location.href =setUrlParams(window.location.href,'_t',Date.now());
}
And you just need to call it:
forceReload();
I've struggled with this for a CSS file that wouldn't refresh. But you can type the name of the CSS file itself into the address bar and refresh that. After that it's fine. Chrome on Android 8. Obviously that would be tiresome if you had more than a couple of files involved.
If that's an option, you can visit the (i.e. JavaScript) resource directly, reload a bunch of times, and that also triggers a hard reload for that resource. Then you can reload the actual page again.
Launch the Chrome Android app
Tap on the menu for more options.
Select Settings from the list of options.
Scroll down and tap on the Site Settings tab.
Within the Site Settings open the Data Stored tab.
Tap on the Site URL that you want to delete storage.
Hit on the Clear & reset command button.
refresh the website page.
there are few methods to force reload chrome on mobile device:
clear history (look above)
use remote debugging (look above)
request desktop site
disable "Lite mode"
open URL for .JS or .CSS then do normal reload.
In chrome,simply tick "Desktop site" and then remove tick!!

How to get Chrome to allow mixed content?

Chrome browser by default is blocking mixed content. How do I adjust my settings/configuration to allow mixed content without making any adjustments on the UI every time?
I have found two solutions but neither of them work:
Several articles say you can adjust this under the Security section
of "Under the Hood" in the Options. This option no longer seems to
exist. There is no Under The Hood tab and there is no such dropdown
to adjust how Chrome handles mixed content as far as I can tell.
Another option is to add the --allow-running-insecure-content flag
to your command line. I did this like so: "C:\Program
Files\Google\Chrome\Application\chrome.exe"
--allow-running-insecure-content. However this made no difference. If I tried adding the flag inside the double quotes, then Windows
complains saying it is invalid.
So what option do I have now with the latest version of Chrome?
Steps as of Chrome v91 (6/17/2021):
Click the Not secure warning next to the URL
Click Site settings on the popup box
Near the bottom of the list is Insecure content, change this to Allow
Close settings, go back to the site, and Refresh the page
Older Chrome Versions:
timmmy_42 answers this on: https://productforums.google.com/forum/#!topic/chrome/OrwppKWbKnc
In the address bar at the right end should be a 'shield' icon, you can
click on that to run insecure content.
This worked for me in Chromium-dev Version 36.0.1933.0 (262849).
In Windows open the Run window (Win + R):
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --allow-running-insecure-content
In OS-X Terminal.app run the following command ⌘+space:
open /Applications/Google\ Chrome.app --args --allow-running-insecure-content
Note: You seem to be able to add the argument --allow-running-insecure-content to bypass this for development. But its not a recommended solution.
The shield icon that is being mentioned was not in the sidebar for me either, however I solved it doing the following:
Find the shield icon located in the far right of the URL input bar,
Once clicked, the following popup should appear wherein you can click Load unsafe scripts,
That should result in a page refresh and the scripts should start working. What used to be an error,
is now merely a warning,
OS: Windows 10
Chrome Version: 76.0.3809.132 (Official Build) (64-bit)
Edit #1
On version 66.0.3359.117, the shield icon is still available:
Notice how the popup design has changed, so this is Chrome on version 66.0.3359.117.
Note: The shield icon will only appear when you try to load insecure content (content from http) while on https.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" " --allow-running-insecure-content"
On OSX using the current Chrome build (2/20/2020, 79.0.3945.130), you can:
Click on the 'i' info icon on the left side of address bar.
Click Site Settings
Scroll down to Insecure content
Change it from Blocked (Default) to Allow
Reload the page and try your action again.
running the following command helps me running https web-page, with iframe which has ws (unsecured) connection
chrome.exe --user-data-dir=c:\temp-chrome --disable-web-security --allow-running-insecure-content
Another solution which is permanent in nature between sessions without requiring you to run a specific command when opening chrome is as follows:
Open a Chrome window
In the URL bar enter Chrome://net-internals
Click on "Domain Security Policy" in the side-bar
Add the domain name which you want to always be able to access in http form into the "Add HSTS/PKP domain" section
On OSX the following works from the command line:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-running-insecure-content
Chrome 46 and newer should be showing mixed content without any warning, just without the green lock in address bar.
Source: Simplifying the Page Security Icon in Chrome at Google Online Security Blog.
You could use cors anywhere for testing purposes. But its note recommend for production environments.
https://cors-anywhere.herokuapp.com/
something like: https://cors-anywhere.herokuapp.com/http://yourdomain.com/api

How to force Chrome's script debugger to reload javascript?

I really like the ability to edit javascript in the chrome debugger however, I find that it can be really problematic getting the debugger to re-fetch the JavaScript from the server.
Sometimes I have to go as far just closing the debugger and reloading the frame works OK - but other times (an dI cannot pin down under what conditions this occurs) I have to clear my temporary internet cache. Sometimes I swear I have to close chrome completely, then clear the cache and then load the page before the debugger finally shows me the most up-to-date script.
(NB. There is no caching of the script by the web server)
I was wondering if anyone knew of a quick and easy way to tell the debugger to invalidate all its javascript and fetch it all anew on page reload?
While you are developing your script, try disabling the Chrome cache.
When you reload the page, the JavaScript should now get refreshed.
Chrome circa 2011
Chrome circa 2018
You can also access it on the network tab:
The context menu shown above is accessible by right clicking / presssing & holding the "reload" button, while Chrome Dev Tools is opened.
Empty cache and hard reload works best for me.
Another Advantage: This option keeps all other opened tabs and website data untouched. It only reloads and clears the current page.
You can always clear a specific file by doing the following:
Open Dev Tools
Click on the Sources tab
Find your script / image / file
Check the right panel to see if your file is up to date
If not:
Right click the resource in the left panel and choose 'Open Link in New Tab'
Force a reload of the resource with the methods above. (See #Bishoy Hanna's example)
This is very handy if you have resources that are in frames and CTRL+F5 is not force refreshing them.
Shift+F5 quickly clears the cache.
Here's a shortcut to DevTools:
F12 to open Chrome DevTools
F1 to open DevTools Settings
Check Disable cache (while DevTools is open) as shown below:
Note: Updated per Dimi's comment. They tend to move it so let me know or update the post if you notice that it's changed.
For Google chrome it is not Ctrl+F5. It's Shift+F5 to clear the current cache! It works for me !
On Windows, Ctrl+Shift+r would force reload the script in chrome.
If you are making local changes to a javascript in the Developer Tools, you need to make sure that you turn OFF those changes before reloading the page.
In the Sources tab, with your script open, right-click in your script and click the "Local Modifications" option from the context menu. That brings up the list of scripts you've saved modifications to. If you see it in that window, Developer Tools will always keep your local copy rather than refreshing it from the server. Click the "revert" button, then refresh again, and you should get the fresh copy.
It seems as the Chrome debugger loads source files into memory and wont let them go despite of browser cache updates, i.e. it has its own cache apart from the browser cache that is not in sync. At least, this is the case when working with source mapped files (I am debugging typescript sources). After successfully refreshing browser cache and validating that by browsing directly to the source file, you download the updated file, but as soon as you reopen the file in the debugger it will keep returning the old file no matter the version from the ordinary browser cache. Very anoying indeed.
I would consider this a bug in chrome. I use version Version 46.0.2490.71 m.
The only thing that helps, is restarting chrome (close down all chrome browsers).
Right click on reload button in chrome and click "Empty Cache and Hard Reload"
If the files which you are loading are cached and if the changes you have made does not reflect in the code then there are 2 ways you can deal with this
Clear the Cache as everyone told
If u want Cache and only the files have to be reloaded , you can go to network tab of the dev tool and clear whatever was loaded. next time it will not load it from cache. you will have your latest changes.
There are also 2 (quick) workarounds:
Use incognito mode wile debugging, close the window and reopen it.
Delete your browsing history
Deactivating Breakpoints caused the new script to load for me.
In my opinion it's easiest to work in a 'private browsing session' of chrome, to ensure that your javascript files don't come from the cache.
If there is document on URL:
file:///C:/Users/user/Desktop/site/index.html
Add any parameter to your URL, like this:
file:///C:/Users/user/Desktop/site/index.html?foo=777
and the browser'll refresh all sites resources
You can also use this Chrome extension to quickly switch between using or not the cache: https://chrome.google.com/webstore/detail/cache-killer/jpfbieopdmepaolggioebjmedmclkbap

Mobile Safari won't stop caching

I'm writing an offline app for mobile Safari.
I have just gotten to the point where it will create the app icon on the home screen and function offline.
Now I want to update the HTML in my app, but it refuses to refresh.
I've trIed the refresh button, the "clear cache" settings option, I have even taken down the server but safari still shows the page.
Help!
You need to modify the cache manifest. You can just add a comment line to the manifest. When you do, the browser will redownload the whole app.
More info about this topic can be found here: http://diveintohtml5.ep.io/offline.html#debugging
Your situation kind of applies to the title :)