How do I make Phantom.js cache resources like a normal browser? - phantomjs

Chrome doesn't re-download javascript files every request. They cache it.
However, when my Phantom.js hits pages, it downloads the javascript every single time. Is there a setting that can make this act like a browser?

PhantomJs already supports in-memory cache ; this means that if you browse multiple pages in side the same running instance, PhantomJs will not download resources already in the cache.
You could turn on disk cache ; this will store web resources (js, css, images, ...) in the physical disk.
This is controlled by a command line parameter :
disk-cache=[true|false] enables disk cache (at desktop services cache storage location, default is false). Also accepted: [yes|no]
max-disk-cache-size=size limits the size of disk cache (in KB).
From this link, it seems to be stored under %AppData%/Local/Ofi Labs/PhantomJS/cache/http. on windows.

Related

Vue PWA Precache manifest versus HTML prefetch link

I'm wondering, when building a Vue PWA app using the CLI and letting all config at default values, my built app is:
prefetching all chunks on initial load using the HTML prefetch links
precaching all chunks using Workbox's PWA mechanism
How do these two mechanisms interact and should I disable one of both?
Thanks!
Prefetch mechanism in index.html <HEAD>:
Precache manifest in service-worker.js:
They clash. The browser downloads them multiple times.
What happens most likely is this (I'm saying most likely because the prefetch link is a hint to the browser and different browsers might implement its use in varying ways and priorities):
Browser fetches the HTML
Browser sees the prefetch links
At some point, browser starts to download the links for later use
When Service Worker is registered, it precaches all the same assets
At later visits/reloads of the page, all of the assets come from the SW's cache and nothing is downloaded again
The double donwload happens because the SW's precache thing uses cache busting and tries to download assets like /realname.hash.js?bla=hash_in_the_manifest_file so even though your files already have the hash values in their names, the precache mechanic is not satisfied with it.
Actually, if you look at the documentation of the Workbox precache plugin you see that they suggest you to drop the revision (hash) checking if you already use hash values in the filenames.

Is browser cache and our system cache (that reside b/w CPU and main memory) are different or same only?

When we browse in the browser for the same website that we have browsed previously then the observe loads it immediately from the cache memory. Similarly when we access some files from our local system's drive then we see that our system shows the recent files(see the image attached) so I am thinking that these files are available in our system cache so it is showing. Now clear me that actually the browser cache and the system cache are different caches or only one cache reside in our whole system?
The browser has its own logical "cache". Every file is stored to the disk and read from there.
The system handles all "file caches" and therefore some data may (still) be in memory when the browser tries to access the file.
These are some different type of "caching" that you're trying to understand.

How to replicate a "Ctrl+F5" page reload in JxBrowser

We have a generated HTML-File on the local filesystem containing some images living on remote server. This HTML-file is being displayed by JxBrowser.
When the images are being changed by our Java Application those images won't update because of clientside caching.
Our most preferred solution would be to offer some sort of "Ctrl+F5"-action by which the enduser itself could clear the cache only for this HTML-file and its resources.
Is there a way to do this with JxBrowser?
To achieve this you can use the reloadIgnoringCache() method of the Browser instance.

How to get Apache to cache video files in memory?

I'm hosting an HLS stream with XAMPP / Apache, which basically means I have a folder in my document root that contains a couple of incrementally numbered 10-second video files.
Every 10 seconds, a new video file is saved into the folder and the oldest video file in the folder is deleted.
Apart from these video files, the document root also contains some other files, such as PHP scripts and playlist files.
My server has plenty of RAM and a pretty fast CPU, but is using a comparatively slow hard disk.
Given the fact that the constant downloading of these video files is likely what's going to make or break the server performance, it seems like a good idea to cache these files in memory.
If Apache were to keep all video files (with a .ts extension) that're downloaded by a user's video player, in it's memory for about 60 seconds, the next user would then be able to download the file much faster. Apache could rely on the files not changing after the first open and on the fact that the files won't be requested anymore after those 60 seconds.
All other files do not (necessarily) have to be cached, since they're rather small and are regularly modified.
Is anyone able to give me directions on how to get started?
Modern operating systems already cache accessed files in memory. The whole process is managed by the kernel automatically.
Apache in-memory caching won't help you since it needs all the files at start-up.
If you want some level of control over the caching you could use vmtouch. Check the manual.

Storing files locally in Node Webkit App

Folks:
I'm creating an app using Node Webkit. The purpose of this app is to display images and pdfs. The app needs to download those files from a central repository, and cache them locally. When the app runs offline, the files should still be available, and displayed.
On the face of it, this sounds like appcache is the answer - and that indeed is where I was heading when this was a pure webapp in a browser. However, now I've discovered node-webkit, and here we are.
node-webkit's GitHub wiki states:
"However, application cache is designed for browser use, for apps using node-webkit, it's less useful than the other two method, read HTML5 Application Cache if you want to use it."
But doesn't say why.
I've also researched node.js filesystem - but that seems like a whole magnitude of complexity above what I need.
Can anyone point me in a sensible direction?
Thanks.
It has to do with the nature of App Cache itself.
You specify a manifest file that lists all the static assets required for your app to run offline. You don't have any programmatic access to the cache to add and remove files via JS.
So for a node-webkit app, it'd make more sense to fetch these files and store them in the Application Support folder (Or AppData, depending on the platform). That's where the node.js part is really useful, the file IO stuff.