Wether you are building a theme or plugin for WordPress, you will typically need to register and load your own Javascript or CSS file at some point. You do this by using the functions provided by WordPress core:

  • wp_register_style – Registers a CSS file
    wp_register_style( string $handle, string $src, array $deps = array(), string|bool|null $ver = false, string $media = 'all' )
  • wp_register_script – Registers a Javascript source (either local or external)
    wp_register_script( string $handle, string $src, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Defining a version

Both of these functions allow you to define a source URL and a few other arguments, but today we’re going to focus on the $ver argument. The $ver or ‘Version’ of your script or style allows you to append a version of your choice as a query string, for instance, these are a few examples from this site:

https://secureservercdn.net/50.62.195.83/f19.e1c.myftpupload.com/wp-content/plugins/better-click-to-tweet/assets/css/styles.css?ver=3.0
https://secureservercdn.net/50.62.195.83/f19.e1c.myftpupload.com/wp-content/plugins/easy-digital-downloads/templates/edd.min.css?ver=2.7.9

Both of the above examples have version numbers appended that reference the currently installed version of those plugins.

Why do we version our assets?

Versioning your assets is super useful for ‘busting cache’ when you release a new version. Modern browsers will cache CSS and JavaScript files locally to the visitor if the URL to the file is the same as it was the last visit. By appending a new version number when you update your theme or plugin, you’re effectively telling all visitors to the site that a new version of the asset is available, and it should re-download it. This prevents you from having to ask the dreaded question of “Did you clear your cache?”

What if I don’t define a version

You may also, from time to time, see plugins and themes have their scripts or styles contain a version that match the currently installed WordPress version, like this:

https://secureservercdn.net/50.62.195.83/f19.e1c.myftpupload.com/wp-content/plugins/plugin-example/style.min.css?ver=4.7.5

In this case, the developer would have chosen to not define a version when registering their styles or scripts. By providing no version, WordPress will append it’s own version.

Should we version external resource?

So what about assets that are external to your server? Things like 3rd party JavaScript resources. For example the Stripe payment gateway has store owners include a JavaScript file directly from their own servers. In this case you want NO version to be appended. Not your plugin’s, theme’s, or WordPress’s version. In this case you must pass in null as the version.

Ways do define your versions

  • String (Ex: ‘2.7.9’) – Results in ../style.css?ver=2.7.9
  • false – Results in ../style.css?ver=4.7.5 (where 4.7.5 will be the current WordPress version)
  • Not defined – Results in ../style.css?ver=4.7.5 (where 4.7.5 will be the current WordPress version)
  • null – Results in ../style.css

Why not use something other than the version?

There have been a few times that a person has asked me why not use something like a timestamp or the last time the file was changed to allow for version busting. While these do work to make sure the user isn’t getting a cached version, there are a few issues that arise.

Using Timestamps

When you use the current timestamp to set your version, that means every time someone visits your page, they’ll have to re-download your assets, since even 1 second later, your timestamp has changed from the last visit. While this helps by never having a cached version of the file, it can hurt your performance by making the user’s browser download files it’s previously downloaded, even though they have not changed.

Using file modification time

In the current space of hosting and multi-server configurations (even in some of the shared hosting world), file modification time could cause similar issues to timestamps. PHP has a function that allows you to get the last time a file was modified, and therefore, that would be the last time the CSS or JS file changed, in theory. All it really means is that’s the last time the file was modified on your servers. If you have a multi-server environment, each server could have a slightly different time that the file was modified, and therefore it’s possible that on subsequent visits to your site, a visitor would request the file from a different server and thus get a different ‘last modified’ time, requiring them to download the file again, even though it’s the exact same file they just requested.

Posted by Chris Klosowski

Chris Klosowski is the Director of Technology at Sandhills Development, LLC, creators of fine WordPress plugins, and ecommerce solutions.

97 Comments

  1. I still see browsers like Chrome ignoring version numbers appended to the end of assets. Until recently they even recommended removing query strings from assets in their PageSpeed stuff, which makes me think they tend to ignore it since they’re encouraging people to use other methods. Personally I think Chrome’s cache is so aggressive it should be considered a bug.

    Anyway, one thing I think we should consider that I don’t see anyone doing is putting the version in the filename itself. When you release version 2.0 of a plugin, and the JS has changed, why not bump the filename? For example, stuff-2017-01-01.js. It would stay at that name until a change is made and when that is released it’s bumped to the release date, for example stuff-2017-06-09.js.

    While that’s a mildly annoying way to manage it, since you have to rename the file and update the filename in the register/enqueue calls, it ensures that browsers like Chrome don’t ruin your day with their buggy cache.

    It’s also worth mentioning Google recommends using this method, in addition to other caching techniques… which, along with my own observations of Chrome’s behavior, makes me think they’re purposely ignoring appended version strings as a reliably cache buster.

    Reply

  2. Hey there I am so excited I found your blog page, I really found you by
    mistake, while I was looking on Askjeeve for something else,
    Anyhow I am here now and would just like to say thanks for a remarkable post and a all round exciting blog
    (I also love the theme/design), I don’t have time to browse it all at the minute but I have book-marked it and also added
    in your RSS feeds, so when I have time I will be back to read
    a lot more, Please do keep up the fantastic work.

    Reply

  3. I am truly pleased to read this weblog posts which carries lots of helpful facts,
    thanks for providing these kinds of data.

    Reply

  4. Pretty section of content. I just stumbled upon your site and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Anyway I’ll be subscribing to your feeds and even I achievement
    you access consistently quickly.

    Reply

  5. authentic viagra buy viagra sydney – will a walk-in clinic prescribe viagra

    Reply

  6. 365 pill viagra define viagra ViagraCND100Mg – where can you buy cheap viagra

    Reply

  7. order amoxicillin no prescription amoxicillin 500 mg cost – buy amoxicillin without prescription

    Reply

  8. amoxicillin 500 mg for sale generic amoxil – purchase amoxicillin 500 mg

    Reply

  9. where can i buy zithromax capsules zithromax online – how much is zithromax 250 mg

    Reply

  10. generic ivermectin stromectol ivermectin for humans – where to buy ivermectin pills

    Reply

  11. stromectol covid ivermectin pills for humans – ivermectin 6

    Reply

  12. п»їorder stromectol online ivermectin 12 mg tablets for sale – ivermectin oral 0 8

    Reply

  13. buy stromectol generic stromectol – buy ivermectin canada

    Reply

  14. male dysfunction treatment prescription drugs online without doctor – drug store online

    Reply

  15. best drugs for erectile dysfunction prescription drugs online without doctor – pharmacy medications

    Reply

  16. ed products ed meds online without doctor prescription – ed pills online pharmacy

    Reply

  17. natural ed medications prescription drugs online without – comfortis without vet prescription

    Reply

  18. hydroxychloroquine 100mg hydroxychloroquine – plaquenil drug

    Reply

  19. ivermectin 250ml buy stromectol – ivermectin generic cream

    Reply

  20. plaquenil brand name plaquenil – hydroxy-chloroquine

    Reply

  21. can i buy lexapro online without prescription Escitalopram – lexapro 20mg pill

    Reply

  22. lexapro tablets price lexaprognr – lexapro prescription

    Reply

  23. real viagra without a doctor prescription ed meds online without doctor prescription – ed treatment review

    Reply

  24. Wonderful goods from you, man. I have understand your stuff
    previous to and you’re just too magnificent. I really like what you’ve acquired here, really like what you are stating and the way in which you say it.
    You make it entertaining and you still care for to keep it wise.
    I can not wait to read far more from you. This is actually a tremendous website.

    Reply

  25. cialis canada purchase cialis no prescription canada – generic cialis florida

    Reply

  26. how to get cialis prescription cialis no prescription canada – cheap viagra and cialis in australia

    Reply

  27. clomiphene tablets cheap clomid – clomid online purchase

    Reply

  28. men ed best ed solution – drug pharmacy

    Reply

  29. viagra price viagra cost – generic viagra walmart

    Reply

  30. canada cialis online cialis discounts – cialis prices at walmart

    Reply

  31. It’s remarkable in favor of me to have a website, which is useful in support of my know-how.

    thanks admin

    Reply

  32. mens ed pills buy cheap prescription drugs online – muse for ed

    Reply

  33. zithromax 250 mg pill zithromax prescription in canada – zithromax 250 mg

    Reply

  34. cost of generic zithromax zithromax antibiotic – zithromax price canada

    Reply

  35. Thanks , I have recently been searching for information approximately this topic for a while
    and yours is the best I’ve discovered till
    now. However, what about the conclusion? Are you certain in regards to the source?

    Reply

  36. generic zithromax azithromycin buy zithromax online – can i buy zithromax over the counter in canada

    Reply

  37. Hey! I understand this is somewhat off-topic but I
    needed to ask. Does building a well-established website like yours require a lot of work?

    I’m completely new to running a blog but I do write in my
    diary everyday. I’d like to start a blog so I will be able to share
    my experience and feelings online. Please let me know if you have any ideas or
    tips for new aspiring bloggers. Thankyou!

    Reply

  38. stromectol coronavirus ivermectin for sale – buy stromectol uk

    Reply

  39. How he makes $300 per day – https://bit.ly/3mOAfVp

    Reply

  40. average cost of prednisone 20 mg cheap prednisone – buy 10 mg prednisone

    Reply

  41. finasteride online bonus finasteride and propecia – propecia cheap

    Reply

  42. Hey there! I know this is kinda off topic however , I’d figured I’d ask.
    Would you be interested in trading links or maybe guest writing a blog article or vice-versa?
    My site goes over a lot of the same subjects as yours and I
    believe we could greatly benefit from each other. If you happen to be interested feel free to send me an email.
    I look forward to hearing from you! Excellent blog by the way!

    Reply

  43. You made some really good points there. I checked on the web for additional information about the issue and found
    most individuals will go along with your views on this website.

    Reply

  44. Thanks for one’s marvelous posting! I definitely enjoyed reading it,
    you could be a great author.I will ensure that I bookmark your blog and may come back very soon. I want to encourage one to continue your great job, have a nice morning!

    Reply

  45. stromectol 3mg tablets ivermectin for humans – can you buy stromectol over the counter

    Reply

  46. ivermectin over the counter canada ivermectin 50 – stromectol tab price

    Reply

  47. buy stromectol canada ivermectin tablets – stromectol covid 19

    Reply

  48. I want to to thank you for this wonderful read!!
    I definitely loved every little bit of it. I have you book marked to check out new stuff you post…

    Reply

  49. buying ed pills online weight loss pills from canada – best ed pills

    Reply

  50. cialis 800 cialis no prescription canada – cialis black 800 mg pill house

    Reply

  51. buy cialis from canada cialis discounts – canadian meds cialis

    Reply

  52. cost of viagra viagra over the counter – cost of viagra

    Reply

  53. male dysfunction pills cheap generic drugs from india – ed meds online without doctor prescription

    Reply

  54. viagra 100mg price viagra without a doctor prescription usa – online doctor prescription for viagra

    Reply

  55. I was very happy to discover this site. I wanted to thank you for ones time due
    to this wonderful read!! I definitely savored every little bit
    of it and i also have you bookmarked to see new information in your
    site. quest bars http://bitly.com/3jZgEA2 quest bars

    Reply

  56. buy cialis online in usa cialis no prescription canada – overnight pharmacy 4u cialis

    Reply

  57. cialis onine cialis pills – free cialis samples canada

    Reply

  58. Thanks for the good writeup. It in truth was a
    leisure account it. Glance advanced to more brought agreeable from you!
    However, how can we keep in touch? asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

    Reply

  59. ivermectin price ivermectin for humans – ivermectin 3

    Reply

  60. ivermectin buy nz buy ivermectin online – ivermectin generic

    Reply

  61. Hi i am kavin, its my first occasion to commenting anyplace, when i read
    this article i thought i could also make comment due
    to this sensible post. scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

    Reply

  62. If some one needs expert view on the topic of blogging after that i
    advise him/her to go to see this web site, Keep up the nice work.

    cheap flights http://1704milesapart.tumblr.com/ cheap flights

    Reply

  63. Hello to every one, since I am genuinely keen of reading this website’s post to be updated on a regular basis.

    It includes good data. scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

    Reply

  64. buy ivermectin nz ivermectin – ivermectin cost

    Reply

  65. I was recommended this website by means of my cousin. I am not certain whether or not
    this post is written through him as nobody else know such targeted about my difficulty.
    You’re wonderful! Thank you! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

    Reply

  66. You can certainly see your enthusiasm within the work you write.
    The arena hopes for even more passionate writers like you who are not afraid to mention how they believe.
    At all times go after your heart. ps4 games https://bit.ly/3nkdKIi ps4

    Reply

  67. ivermectin oral solution buy ivermectin online – cost of ivermectin medicine

    Reply

  68. ivermectin 250ml cost of ivermectin lotion – ivermectin cream uk

    Reply

  69. aspirin and ed ed treatment drugs – ed meds pills drugs

    Reply

  70. solutions for ed best canadian pharmacy online – erectial disfunction

    Reply

  71. do i have ed cheap drugs online – aspirin and ed

    Reply

  72. erection pills viagra online ed doctors – buy medications online

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *