Is the fileExists remote file checking uses cfhttp head?
I'm concerned on the speed of fileExists over CFHTTP when checking remote files
<cfset imgExist = FileExists('https://qph.fs.quoracdn.net/main-qimg-e8b07145ae25974d4902168818241326.webp') >
<cfdump var="#imgExist#">
-- Returns Yes --
Is the FileExists function uses CFHTTP head?
<cfhttp method="head" url="someimage" resolveurl="no" throwonerror="no" timeout="2" />
What is the advantage of FileExists over CFHTTP when checking if the remote file exists?
Also is FileExists better than CFHTTP in terms of server load?
Is the FileExists function uses CFHTTP head?
Yes, fileExists
utilizes the Commons Virtual File System, which translates to a HTTP HEAD request for web resources.
What is the advantage of FileExists over CFHTTP when checking if the remote file exists?
Theoretically the implementation could easily adjust to specific rules for web resources, while using cfhttp
would be a concrete implementation. However, you could just wrap cfhttp
to easily adjust it yourself, rather than relying on the newest version of Jakarta VFS.
Also is FileExists better than CFHTTP in terms of server load?
No, right now both calls result in a HTTP HEAD request. I could not measure a real performance difference between them.
As mentioned in the comments, you should probably NOT use fileExists
, because:
fileExists
.So my recommendation is: Write a neat function that uses cfhttp method="HEAD"
and adjust the function whenever you need to. Don't trust an undocumented feature, especially not when it comes to CF. 😜