Skip to content

Instantly share code, notes, and snippets.

@baires
Forked from necolas/.htaccess
Created June 12, 2012 05:28
Show Gist options
  • Select an option

  • Save baires/2915330 to your computer and use it in GitHub Desktop.

Select an option

Save baires/2915330 to your computer and use it in GitHub Desktop.

Revisions

  1. @necolas necolas revised this gist Apr 11, 2012. 3 changed files with 13 additions and 7 deletions.
    4 changes: 4 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    # Filename-based cache busting
    # taken from https://github.com/h5bp/html5-boilerplate/

    # This rewrites file names of the form `name.123456.js` to `name.js`
    # so that the browser doesn't use the cached version when you have
    # updated (but not manually renamed) the file.

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    12 changes: 6 additions & 6 deletions build.sh
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,8 @@
    # being in a `js` directory.


    # concatenate and minify the CSS
    # requires: Sass (Ruby)
    # Concatenate and minify the CSS
    # Requires: Sass (Ruby)

    END_CSS="style.css"
    END_MIN_CSS="style.min.css"
    @@ -23,15 +23,15 @@ $SASS_COMMAND compressed scss/style.scss:$END_MIN_CSS

    echo "SCSS-to-CSS build compilation successful"

    # concatenate all JS files
    # explicitly name and order the files if needed
    # Concatenate all JS files to into `site.js`
    # Explicitly name and order the files if needed

    cat js/*.js > js/site.js

    echo "JS concatenation successful"

    # minify the combined JS
    # requires: UglifyJS (Node)
    # Minify the combined JS
    # Requires: UglifyJS (Node)

    uglifyjs --output js/site.min.js js/site.js

    4 changes: 3 additions & 1 deletion functions.php
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,8 @@ function is_prod() {

    /*
    * Basic file versioning
    * Note: probably better to use `md5_file` instead of `filemtime`
    * http://www.php.net/manual/en/function.md5-file.php
    */

    function version($filename) {
    @@ -24,7 +26,7 @@ function version($filename) {
    //check if the file exists
    if (file_exists($pathToFile)) {
    $needle = '.';
    // return the versioned filename
    // return the versioned filename based on the last modified time
    $versioned = '.' . filemtime($pathToFile) . '.';
    // the position of the last instance of '.'
    $pos = strrpos($filename, $needle);
  2. @necolas necolas revised this gist Apr 11, 2012. 2 changed files with 11 additions and 1 deletion.
    3 changes: 3 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # taken from https://github.com/h5bp/html5-boilerplate/

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
    9 changes: 8 additions & 1 deletion build.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,16 @@
    #!/bin/sh

    # Run `bash build.sh` whenever you need to perform these tasks
    # Run `bash build.sh` from within the theme's directory whenever
    # you need to perform these tasks.

    # A separate `watch.sh` script is better for continuous compilation
    # of `.scss` files during development.

    # Update any paths as needed. This example relies on all the theme's
    # `.scss` files being in a `scss` directory, and all the `.js` files
    # being in a `js` directory.


    # concatenate and minify the CSS
    # requires: Sass (Ruby)

  3. @necolas necolas revised this gist Apr 9, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions build.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    #!/bin/sh

    # Run `bash build.sh` whenever you need to perform these tasks
    # A separate `watch.sh` script is better for continuous compilation
    # of `.scss` files during development.

    # concatenate and minify the CSS
    # requires: Sass (Ruby)

  4. @necolas necolas revised this gist Apr 9, 2012. 2 changed files with 12 additions and 6 deletions.
    6 changes: 5 additions & 1 deletion functions.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    /*
    * Check environment
    */
    @@ -35,4 +37,6 @@ function version($filename) {
    // return the original filename
    return '/' . $filename;
    }
    }
    }

    ?>
    12 changes: 7 additions & 5 deletions header.php
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    <?php
    // other code

    // only reference the minified file in production
    // version which ever file is referenced
    is_prod() ? $cssfile = 'style.min.css' : $cssfile = 'style.css';
    echo '<link rel="stylesheet" href="' . get_bloginfo('stylesheet_directory') . version($cssfile) . '">';
    // other code

    // only reference the minified file in production
    // version which ever file is referenced
    is_prod() ? $cssfile = 'style.min.css' : $cssfile = 'style.css';
    echo '<link rel="stylesheet" href="' . get_bloginfo('stylesheet_directory') . version($cssfile) . '">';

    ?>
  5. @necolas necolas created this gist Apr 9, 2012.
    8 changes: 8 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Filename-based cache busting
    # taken from https://github.com/h5bp/html5-boilerplate/

    <IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
    </IfModule>
    29 changes: 29 additions & 0 deletions build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/sh

    # concatenate and minify the CSS
    # requires: Sass (Ruby)

    END_CSS="style.css"
    END_MIN_CSS="style.min.css"
    SASS_COMMAND="sass --load-path scss --style"

    $SASS_COMMAND expanded scss/style.scss:$END_CSS
    $SASS_COMMAND compressed scss/style.scss:$END_MIN_CSS

    echo "SCSS-to-CSS build compilation successful"

    # concatenate all JS files
    # explicitly name and order the files if needed

    cat js/*.js > js/site.js

    echo "JS concatenation successful"

    # minify the combined JS
    # requires: UglifyJS (Node)

    uglifyjs --output js/site.min.js js/site.js

    echo "JS uglification successful"

    exit 0
    38 changes: 38 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    /*
    * Check environment
    */

    function is_prod() {
    if ( home_url() == '<production-url>' ) {
    return true;
    }
    else {
    return false;
    }
    }

    /*
    * Basic file versioning
    */

    function version($filename) {
    // get the absolute path to the file
    $pathToFile = TEMPLATEPATH . '/' . $filename;

    //check if the file exists
    if (file_exists($pathToFile)) {
    $needle = '.';
    // return the versioned filename
    $versioned = '.' . filemtime($pathToFile) . '.';
    // the position of the last instance of '.'
    $pos = strrpos($filename, $needle);
    if ($pos !== false) {
    // replace and return
    return '/' . substr_replace($filename, $versioned, $pos, strlen($needle));
    }
    }
    else {
    // return the original filename
    return '/' . $filename;
    }
    }
    8 changes: 8 additions & 0 deletions header.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <?php
    // other code

    // only reference the minified file in production
    // version which ever file is referenced
    is_prod() ? $cssfile = 'style.min.css' : $cssfile = 'style.css';
    echo '<link rel="stylesheet" href="' . get_bloginfo('stylesheet_directory') . version($cssfile) . '">';
    ?>