Coder Social home page Coder Social logo

resource-versioning's Introduction

Resource Versioning

Turn Query String Parameters into file revision numbers.

It’s important to make resources (images, scripts, stylesheets, etc.) cacheable.

Steve Souders

It is much easier to use a CDN without Query String Parameters. This plugins alters only local resources' URL-s. The ver Query String Parameter will be inserted into the filename.

jquery.min.js?ver=1.10 becomes jquery.min.110.js

To "revert" that change add this line to your nginx config:

server {
    location ~ ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ {
        #try_files $uri $1.$2 /index.php?$args;
        try_files $uri $1.$2 =404;
    }
}

Or to your Apache config or .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.\d\d+\.(js|css|png|jpg|jpeg|gif|ico)$ $1.$2 [NC,L]

Testing the plugin before live usage

You can test the plugin by replacing the two add_filter() calls with this

require_once dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/wp-load.php';
wp();
echo o1_revving_src( $argv[1] ) . PHP_EOL;

Then start it from CLI: php revving.php <TEST-URL>

How to remove all Query String Parameters from resources?

Poorly written plugins and themes may add unwanted Query String Parameters. For example ?rev=4.10.

To drop all these parameters copy this into your wp-config.php

define( 'O1_REMOVE_ALL_QARGS', true );

resource-versioning's People

Contributors

szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.