Google – Chrome – Clean up JavaScript Cached files

Background

Eyes set on Google news for a bit of distraction.

Adrian Kingsley-Hughes

Saw an article by Adrian Kingsley-Hughes :-

Titled :- These hidden cache files are bloating your Google Chrome
SubTitle :- Google Chrome could be storing a hundred thousand cached files on your computer, and it doesn’t give you a way to delete them.
Link :- Link

Timeline

  1. Google Chrome, The Storage Hoarder
    • Date Published :- 2019-April-25th
      Link

Explore

Let us look at one of our machines and see what it looks like.

OS – MS Windows

Folder

On MS Windows, Google’s Chrome User Data is saved here :-

  1. User Data
    • Pattern
      • C:\Users\<username>\AppData\Local\Google\Chrome\User Data
    • Sample
      • C:\Users\dadeniji\AppData\Local\Google\Chrome\User Data
  2. Code Cache – JavaScript
    • Pattern
      • C:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default\Code Cache\js
    • Sample
      • C:\Users\dadeniji\AppData\Local\Google\Chrome\User Data\Default\Code Cache\js

Explorer

File Listing

Image

cache.javascript.windows.explorer.01.20200403.0710PM.PNG

Explanation
  1. Number of Files :- 110,613 items
  2. Files
    • File Names
      • Data Files
        • *_0
      • Index Files
        • index
      • Index-dir
        • File Folder

Files – Storage Used

Image

cache.javascript.windows.explorer.storageUsed.jsproperties.01.20200403.0711PM.PNG

Explanation
  1. Size :- 35.1 MB
  2. Size on disk :- 47.3 MB
  3. Number of Files :- 21,655 Files

 

Code

Outline

  1. Identify Google Chrome JavaScript Code Cache Folder
    • OS Environment Variable
      • APPDATA
        • C:\Users\dadeniji\AppData\Roaming
      • LOCALAPPDATA
        • C:\Users\dadeniji\AppData\Local
  2. Get Total In Use Files Size
    • Issue dir
      • Parse output of dir command
        • Look for the word bytes
        • Then parse for Files
  3. If parameter cleanup passed in, please remove files
    • Command – forfiles
      • parameters
        • /p
          • <folder>
        • /m
          • *_0
        • /C
          • cmd /C dir /b @path & del @path
            • dir /b @path
              • list file name
            • del @path
              • delete file
            • &
              • concatenate command

Script

Here is a script cleaning things up on MS Windows


@echo off
setlocal

set "_appData=%APPDATA%"

set "_appDataLocal=%LOCALAPPDATA%"

set "_googleChromeCodeCacheJS=%_appDataLocal%\Google\Chrome\User Data\Default\Code Cache\js"

dir "%_googleChromeCodeCacheJS%" | findstr "bytes" | findstr "File"

IF [%1]==[] ECHO Please pass in cleanup to actually cleanup

if "%1" == "cleanup" (

	if exist "%_googleChromeCodeCacheJS%"\*_0 (

		echo cleaning up ...

		forfiles /p "%_googleChromeCodeCacheJS%"  /M "*_0" /C "cmd /C dir /b @path & del @path "

		echo cleaned up

	)

)

:complete

endlocal

Output

files.exists.01.20200403.0749PM

Output

files.exists.cleanup.01.20200403.0749PM

 

Source Code

Github

Gist

DanielAdeniji/pruneGoogleCacheJavaScript.cmd
Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s