PHPackages                             fballiano/openmage-cssjs-versioning - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fballiano/openmage-cssjs-versioning

ActiveMagento-module[Utility &amp; Helpers](/categories/utility)

fballiano/openmage-cssjs-versioning
===================================

CSS/JS versioning module for OpenMage (and Magento 1.9)

0.3.0(2y ago)4182OSL-3.0PHPPHP &gt;=7.4.0

Since Apr 15Pushed 2y ago2 watchersCompare

[ Source](https://github.com/fballiano/openmage-cssjs-versioning)[ Packagist](https://packagist.org/packages/fballiano/openmage-cssjs-versioning)[ Docs](https://github.com/fballiano/openmage-cssjs-versioning)[ Fund](https://www.buymeacoffee.com/fballiano)[ Fund](https://paypal.me/fabrizioballiano)[ RSS](/packages/fballiano-openmage-cssjs-versioning/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

CSS/JS Versioning module for OpenMage/Magento1
==============================================

[](#cssjs-versioning-module-for-openmagemagento1)

**If you find my work valuable, please consider sponsoring**
[![Sponsor me on GitHub](https://camo.githubusercontent.com/3f9a3c47d5a6c575b4d6c5f13ecaf55ff585c67a6ba47f87f8cf57e4cb7a1fdc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f722d3330333633443f7374796c653d666f722d7468652d6261646765266c6f676f3d4769744875622d53706f6e736f7273266c6f676f436f6c6f723d237768697465)](https://github.com/sponsors/fballiano "Sponsor me on GitHub")[![Buy me a coffee](https://camo.githubusercontent.com/430a7d4ff7294cc857ec60d5ea9f51241205a91cab8387143d33b4bd13e27912/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275795f4d655f415f436f666665652d4646444430303f7374796c653d666f722d7468652d6261646765266c6f676f3d6275792d6d652d612d636f66666565266c6f676f436f6c6f723d626c61636b)](https://www.buymeacoffee.com/fballiano "Buy me a coffee")[![Donate via PayPal](https://camo.githubusercontent.com/b811c9741e973ac713b2a33c9bfd025f0fad57a7b1d57a29d03b30badb6d04f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617950616c2d3030343537433f7374796c653d666f722d7468652d6261646765266c6f676f3d70617970616c266c6f676f436f6c6f723d7768697465)](https://www.paypal.com/paypalme/fabrizioballiano "Donate via PayPal")Quick description
-----------------

[](#quick-description)

Adds `?v=` to all your CSS/JS and the value of `v` is the last git commit hash.

Rationale
---------

[](#rationale)

To make search engines happy you need to use very long browser's cache lifetime (with or without a CDN), but if you tell browsers to cache a css or a js for 1 year and then you need to modify it? The browsers won't receive the new version and your website will break.

My solution is to add a `v=xxx` parameter to all CSS/JS URLs, this way the cache will be forced to update and the new version of the files will be stored in cache until the next update.

In order to do that reliably and consistently I've created this module that intercepts the http\_response\_send\_before event, uses as little preg\_regex as possible in order to be as performant as possible to add the `v=xxx` parameter.

This approach should work also with full page cache modules.

Features
--------

[](#features)

**How to gen the version number to use in the `v=xxx` parameter?**

This module supports 2 approaches:

1. using the last `Git commit hash` (only the first 6 characters) as the version number
2. if that fails then a timestamp is used

The git method is preferred because the generated version number won't change unless a new change is pushed on the repository. However, in order to work, OpenMage base dir must also be the Git project root directory and the .git folder has to be present in all servers you need this functionality to work.

**Resuming:**

- Automatically reads the last Git commit hash, extracts the first 6 characters
- Saves this version number in OpenMage config cache for 1hour (if you flush config cache you also flush this value) in order to have a little impact on the filesystem as possible
- If the git approach doesn't work, the version number because the current timestamp (and gets cached for 24 hours)
- Parsed the output HTML and intercepts all `
