Adding a query line to all files in a folder

53 views
Skip to first unread message

Peter Small

unread,
Jun 17, 2021, 10:33:28 AM6/17/21
to BBEdit Talk
Chrome keeps caching my files so that when I make a change to any online document Chrome displays the cached version and not the modified version that is on the server.

To get over this problem I want to append a version number in a query line to every document  i.e., by adding "?v=1.0" to the end of all the documents (URLS, CSS and JS docs). I want to be able to do this first in a folder on the desktop.

Can this be done as a batch with BBEdit? Or perhaps there is an Applescript or Keyboard Maestro macro out there somewhere?

Grateful for any suggestions.

Media Mouth

unread,
Jun 17, 2021, 10:53:40 AM6/17/21
to BBEdit Talk
I think it's the other way around -- you want the browser to request files with an ever-changing query string (the text after the ?) (file://path/to/file.ext?everChangingToBypassCache)
The filenames themselves remain unchanged.

Neil Faiman

unread,
Jun 17, 2021, 11:16:19 AM6/17/21
to BBEdit Talk Mailing List
On Jun 17, 2021, at 10:31 AM, Peter Small <pe...@stigmergicsystems.com> wrote:

To get over this problem I want to append a version number in a query line to every document  i.e., by adding "?v=1.0" to the end of all the documents (URLS, CSS and JS docs). I want to be able to do this first in a folder on the desktop.

Can this be done as a batch with BBEdit? Or perhaps there is an Applescript or Keyboard Maestro macro out there somewhere?

I assume your point is that you aren't actually changing the file names, just adding a query string to the anchors and links that refer to the. If so, here's a quick and dirty approach.

Make sure your query identifier string is unique across your entire site. Maybe “?reloadVersion=version” or something equally ugly.

Now just do a site-wide search-and-replace. Cmd-Shift-F to open the multi-file search dialog. Search string: “\?reloadVersion=[\d.]+“. Check Grep. Replacement string “?reloadVersion=yourNewVersionNumber”. Search in: Frontmost Project (assuming your site is kept as a BBEdit project). Click Replace All.

Specifying a new version each time is up to you. You can probably automate it with AppleScript, but probably not worth the time. But if you do want to do it, I'd suggest just using something like  "YYYYMMDDHHMMSS" for the version string — guaranteed unique, no cleverness required.

Regards,

Neil Faiman

Nestor Aguilera

unread,
Jun 17, 2021, 11:22:08 AM6/17/21
to BBEdit Talk
Will this link help?

https://superuser.com/questions/1121716/how-do-i-force-chrome-to-load-a-fresh-copy-of-a-page

Best, Nestor

===============================================
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/a282fe2f-514c-4f78-aceb-c057e3e94b70n%40googlegroups.com.

Greg Raven

unread,
Jun 18, 2021, 8:08:47 AM6/18/21
to BBEdit Talk
This sounds like a good reason not to use Chrome, but in your shoes I think I would select those files in the Finder and right-click to bring up the Rename function. I'll bet this could even be automated.

Peter Small

unread,
Jun 19, 2021, 8:40:39 AM6/19/21
to BBEdit Talk
What I ended up doing was to download all the files on my website (www.dinnerpartytown.uk) then with BBEdit's multiple file search I made the following replacements:
 ".html" replaced with ".html?v=1.0"
".js" replaced with ".js?v=1.0"
".css" replaced with ".css?v=1.0"
".jpg" replaced with ".jpg?v=1.0"
I then uploaded all the files to the server and everything seems to work fine. 
I'm hoping this will allow me to make changes that will not be ignored through visitor browser caching.

Gerald Davenport

unread,
Jun 19, 2021, 3:10:16 PM6/19/21
to bbe...@googlegroups.com
Greetings al, and Peter Small.

I have ran into many different issues when dealing with web design and browser cache when testing a quick fix with css, an image, or anything that the browser (or the hosting server) has stored.

I use https://chrispederick.com/work/web-developer/ in all browsers: chrome, Firefox, brave, opera, and edge.

I use Webdevloper extension to clear cache much easier than going into the browser prefs.

When some of my development is using a main.css that includes all the other css files and main.css?ver=3 going to ver=4 does not work, I sometimes have to close the current tab I am in and open the site in a new one.

Web developer also allows you to remove session cookies, which does help.

The other issue I ran into that changing version (?ver=) does not help at all. The reason is that the server (siteground - not mine but some places I do web work for use) they have a built in cache for all pages and sites which frustrates me to wanting to do terrible things.

I understand it makes the site go faster (in theory) but I cannot see any changes made to see if they work live and not just local. You should always verify the live site is what the local site is. anyway. I have to go into Wordpress and use their plugin to clear site wide cache.

Siteground gave me some code to add to htaccess but it does not work.

So you may want to find out if your host has a built in automatic cache on your site before pulling your hair out.

- gerald

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.

Byers Home Page

11773 Slow Poke Lane, Grass Valley, California 95945
Byers is committed to protecting your health and safety with a Virtual Consultation.

Reviews on Google • Give Us Feedback

We are here to help you Stay Safe!

@lbutlr

unread,
Jun 19, 2021, 6:26:34 PM6/19/21
to BBEdit Talk
On 17 Jun 2021, at 08:31, Peter Small <pe...@stigmergicsystems.com> wrote:
> Chrome keeps caching my files so that when I make a change to any online document Chrome displays the cached version and not the modified version that is on the server.

Are you setting an expiration header on you site? This is normally how you prevent caching.

Also, I believe in Chrome (and other browsers) ⇧⌘-R or perhaps ⌥⌘-R will reload the page from the server and not from cache.

Or, you can go all in and add http headers:

Cache-Control: no-cache, no-store, must-revalidate
Expires: 0

In Apache you would add this like so:

<IfModule headers_module>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Expires "0"
</IfModule>


--
"He is simply a shiver looking for a spine to run up." - Paul Keating

pe...@stigmergicsystems.com

unread,
Jun 20, 2021, 5:17:33 PM6/20/21
to bbe...@googlegroups.com
Thank you for your suggestions.

As I'm new to this problem of caching I'm stumped by simple things that to
most people seems blatantly obvious.

Firstly, I don't have a problem myself with getting a server side version
of a web page as I can use command-R when Chrome caches it. It is the
visitors to the site I'm concerned about.

As I have many images on my site I need to keep costs down by allowing as
much caching as possible. So, what I need is a way to add something to a
web page so that after I make an update to it this new version is read
instead of the cached version.

Can I do this in the HTML document without having to do anything on the
server side?
I'm advised meta tags are not reliable for this.

HTTP headers seem to be the most recommended solution, but these
recommendations never seem to come with enough instructions for newbies to
be able to apply them.

I can get to the apache .htaccess file but all the instructions I come
across totally confuse me.

What I'd like to be able to do is allow full caching for most of my site
content but be able to arrange to have a select a few files not cacheable
(sort of like setting a class in css). Is this possible?

Specifically, I'd like to know what I'd have to put in an HTML doc header
and what to put in the .htaccess file.

Grateful for any help with this.
> --
> This is the BBEdit Talk public discussion group. If you have a feature
> request or need technical support, please email "sup...@barebones.com"
> rather than posting here. Follow @bbedit on Twitter:
> <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bbedit/85A7EAF6-1AC3-4E76-8A3C-B315D7F4D069%40kreme.com.
>


pe...@stigmergicsystems.com

unread,
Jun 20, 2021, 5:17:36 PM6/20/21
to bbe...@googlegroups.com
Thank you Gerald,

That seems really useful advice.
As I look more and more into caching I'm finding a real Pandora's box.
There seems to be no universal solution, so, its bottom up, try and test
from here on.
>> <https://twitter.com/bbedit <https://twitter.com/bbedit>>
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "BBEdit Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to bbedit+un...@googlegroups.com
>> <mailto:bbedit+un...@googlegroups.com>.
>> <https://groups.google.com/d/msgid/bbedit/b34408c7-7344-400c-8c3e-35d7c30c47e4n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
> --
>
> <https://thatsbyers.com?utm_source=GmailFooter&utm_medium=ThatsByers&utm_campaign=EmailSignature>
>
>
> 11773 Slow Poke Lane, Grass Valley, California 95945
> Byers is committed
> to protecting your health and safety with a Virtual Consultation.
> <https://thatsbyers.com/virtual-consultation>
>
> Reviews on Google
> <https://www.google.com/search?hl=en-US&gl=us&q=Byers,+11773+Slow+Poke+Ln,+Grass+Valley,+CA+95945&ludocid=11748852054921487165&lsig=AB86z5XcBI1O6r_L8QktB46n23GB#lrd=0x809b705409fd6757:0xa30c4eb22436a33d,3>
> * Give Us Feedback
> <https://thatsbyers.com/about/reviews?utm_source=GmailFooter&utm_medium=signaReviewsture&utm_campaign=EmailSignature>
>
> We are here to help you Stay Safe!
> <https://thatsbyers.com/lpmicro/stay-safe/?utm_source=EmailFooter>
>
> --
> This is the BBEdit Talk public discussion group. If you have a feature
> request or need technical support, please email "sup...@barebones.com"
> rather than posting here. Follow @bbedit on Twitter:
> <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "BBEdit Talk" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/bbedit/NeTy-8EAAUM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> bbedit+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bbedit/19C7D2F6-C21D-4DC2-B100-2AE485C3E069%40thatsbyers.com.
>


Greg Raven

unread,
Jun 20, 2021, 5:28:28 PM6/20/21
to BBEdit Talk
Caching can be complicated to manage, which is why it's usually easiest (and best) to leave it to experts. As for as keeping costs down, your site seems pretty simple, so it might be possible to move it to Netlify.


Not only do they offer an insanely great free tier, but they manage all the caching as all files are served from their CDN.

MediaMouth

unread,
Jun 20, 2021, 5:42:31 PM6/20/21
to bbe...@googlegroups.com
I've never found header controls to be particularly reliable when trying to manage caching. And renaming files seems a frustrating approach Among the most reliable methods involves the use of query strings.

There are a lot of ways to approach this, and your control can be as global or granular as you want. So if you need certain html content to loaded definitively not from cache but the <img> tags within to remain cache, it can be done.

One option might be to put content not to be cached in an iframe, eg <iframe src="path/to/nocache.html?ver2or3or4etc">. <img> tags within would have no such query strings, so would cache.

This way you do not have to actually rename your html files at all, just update the query strings.

This is a handy way to work without resorting to JS. BUT a minimum of browser side JS code could do a lot to make the whole thing easier to manage.

> On Jun 20, 2021, at 14:17, pe...@stigmergicsystems.com wrote:
>
> Thank you Gerald,
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/8859989bac3f7a5eef5fa9ed67d6ca2f.squirrel%40email.powweb.com.
Reply all
Reply to author
Forward
0 new messages