ChatGPT解决这个技术问题 Extra ChatGPT

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?

Just returned to extend (what had been) a stable web-app, and discovered that this was happening. The latest state data is stored in a .js file with a cache-buster url suffix. This no longer works, in Chrome on Windows, ChromeOS or Android.
it seems like a simple refresh (clicking the circle w arrow) detects any changes these days. no tricks. ...let me know if I'm wrong.

C
Community

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.


Simply type it to the address bar prefixing the code with javascript:.
Actually, you should be able to avoid window. part. javascript:location.reload(true) should do the trick.
didn't work for me on chrome v55.0.2883.91/android5.1.1
It doesn't work on mine, v56.0.2924.87 on Android 7.1.1. Why can you just hit refresh and have the browser re-download like it used to work? Such an annoyance when trying to develop.
I open up an Incognito window
M
Michael

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.


@Kev Neither for me.
Yes, this one is working for me on Android 6.0.1 with Chrome 59.
This works better than the accepted answer, at least on on Android 7.1.2 and Chrome 61. The caching is really aggressive somehow. Even emptying cached files for that domain did not work for me.
I use it more often, if it isn't working for you probably the cache is on the server and not the browser.
It will clear cache in incognito mode only the first time. After that the same issue appears
A
Alec

Also an option:

Menu Settings Privacy Clear Browsing Data Check "Cache" and press "CLEAR"

and then reload the page.


Now its changed to Clear Browsing Data, where you can check clear cache using check box.
No, and then, KILL Chrome, relaunch Chrome, then reload the page. Yeah, it just got worse.
Update: Even killing Chrome doesn't work anymore. I have NO idea what the hell the option "Cached images and files" is clearing.. it still holds on to the cached CSS file. This is getting more ridiculous!
Update: See heidgert's answer. Clearing cache might still load "cached" result from Google's servers if "Data Saver" is turned on in Chrome settings.
This will clear the cache from ALL sites, not just the inspected one .
I
Ishmaeel

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.


Confirmed working on Chrome. I almost missed this answer while skimming. Removed the comments about Firefox to help the next person. I hope this doesn't come across as conflicting with author's intent.
This is by far the best answer for development when you get a stuck css or js file. I find usually refreshing works fine, but sometimes for some inexplicable reason a js or css file gets stuck, and this is the only way to unstick it that I've found. Wish I could give more than 1 upvote, lol, because it's such an easy fix.
This used to work a while back, but does not anymore on any recent version of chrome as of december 2017.
This worked for me with Chrome 2018 65.0.3325.109 on Samsung Android 5.1.1; SM-T900 Build/LMy47X. It had the additional benefit of not destroying cached data (such as localStorage values).
Does not work in Apr 2019. Chrome 73+ does not work.
A
Aakash Goel

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!


this comment is out of date but put me on the right track. You have to enable the actual phone for debugging via Chrome first.
For detailed instructions on how to enable USB debugging on an Android phone, see: stackoverflow.com/a/16707217/1024735 . And this feature is awesome for more than just the hard reload ability. Thanks!
For testing in the Android emulators Ctrl+Shift+R in devtools is really nice and quick. No turning any settings on and off etc. Thanks.
y
yPhil

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

https://i.stack.imgur.com/CMrDT.jpg

2 - tap "Site settings"

https://i.stack.imgur.com/7SCtK.jpg

3 - Tap the trashcan icon

https://i.stack.imgur.com/g7H9j.jpg

That's it, even the most deeply ensconsed service worker for that URL will now die.


This does not work on Chrome 73.0.3683.90 on a Samsung S9+. I have tried this over 15 times, as well as javascript:location.reload(true), and it does not work. It seems Android users cannot also be developers, according to Guug-Ul, lord of darkness.
Works on my Note 8.. But I have to refresh the page after.
You can also get this menu by clicking the lock icon (or whatever it displays for insecure connections) to the left of the URL.
By far the best solution ! <3
Works like a charm! Thanks for the answer...!
h
heidgert

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 THINK this setting is now simply called "Data Saver".
L
Lucas Zamboulis

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


This works. Just ?a is sufficient if you only want to reload once.
This is not very feasible for reloading cached reference files (like CSS or JS), since you can't really edit the main HTML to add the ?a - of course, unless you're the site host.
S
Skippy le Grand Gourou

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.


Note step 3: choose the time period. This did the trick for me since I was trying to clear cached pages from 3 weeks ago.
It's not your fault but this is a pretty terrible solution as it clears the browsing data for all other sites too, which is a pain if you use your browser for anything other than dev work!
@GameKyuubi Actually, if you select data from last hour the pain is limited. But of course this solution is quite poor, I only referenced it because it's the official one and it does work (contrarily to a few others).
That's kind of what I mean, the fact that this is the official solution is downright embarrassing.
Great solution because this offers you the option of clearing cached data without clearing cookies or history
B
Bort

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:

https://i.stack.imgur.com/hkRMK.png

2. Clear Chrome's cache

Select "Storage" from the same screen:

https://i.stack.imgur.com/e5EtE.png

Finally, select "Clear cache".

https://i.stack.imgur.com/4izVU.png

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.


Perfect, that's the only solution that worked for me without USB debugging.
N
Nathan Osman

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


awesome solution, this works mainly for "inspect" the webpage of the device directly on desktop, and you can clear cache too. Thanks.
This is actually the most beautiful answer.
This is the only answer that worked for me; thanks for posting!
G
Greg Searle

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).


Interesting, I wasn't aware of this. Do you have any source that supports this claim?
This is just observed behavior as I develop my own Javascript apps. I had to specify the CACHE-CONTROL:NO-CACHE directive in the HTTP header from my development web server to keep from going crazy over bugs that just wouldn't go away (because Chrome was insisting on caching old code). Firefox doesn't display this behavior.
This is the only think that worked for me out of all the answers. I had a dummy post request in javascript writing to an SQL table to check if it really refreshes and this solution got it right. Moreover subsquent site visits without the url addition are now behaving as expected. Edit: It stopped working :) I think it must have been a combination of all the stuff I tried on here haha
The only effective solution I have found for this is to actually change the file name by appending a version number to it (and all the complications this involves). Looks like other developers have adopted this solution as well. So be it.
佚名

Remote Debugging allows you to use the desktop dev-tools:

https://developers.google.com/chrome-developer-tools/docs/remote-debugging


yes thanks I know that already - should have mentioned this, but sometimes I don't want to plug it in but still have this option
You can clear the cache like this: support.google.com/chrome/answer/2392709
Thanks, an option without flushing the whole cache for all sites would be nice though
This is the most reliable option when you enable Network > Disable Cache
D
Dharman

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.


Underrated great answer!
n
namp

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.


This was the only solution that worked for me - enter the keys on the address bar of the page you're on, Samsung S20 FE + Chrome. Even manually typing in CSS & JS paths and refreshing, even though I could see my new code, it wouldn't apply. Tried everything else here! Note the new page will work incognito - but that's not always what you want. Thanks for this off-beat but working solution - I just wonder how long until Google disables this on Android (like using Ctrl & function keys, etc).
u
user1937747

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.


This works on may 2022, doing the same for css and js files independently.
This also worked for an SVG image that was giving me a hard time. Accessing the image URL directly and reloading was already showing the new version but in the page it would not update until I tried this trick. Not sure if this applies to other image types.
T
Tom Kay

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

https://i.stack.imgur.com/3rjvzm.png

Then click the little arrow in the top right

https://i.stack.imgur.com/Q8A5Km.png

Select "clear cache" from that menu.


In Chrome 75, chrome://net-internals says "The net-internals events viewer and related functionality has been removed..."
@Bort thanks for the heads up. It looks like this method won't work any more.
D
DirkTheWebPhoenix

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.


Sadly this is the only one that seems to work nowadays. It does mean whenever working on css you need to keep updateing functions.php in wordpress to up the version. Yes another stupid thing about google, who fail to think and are right up there with microsoft now. But yes, an old trick :)
M
MSS

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();

B
Bob Warwicker

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.


P
PCcloob.Ir

In chrome,simply tick "Desktop site" and then remove tick!!


W
WoodrowShigeru

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.


D
Dip Vachhani

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.


u
uingtea

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.