Coder Social home page Coder Social logo

grunt-cache-bust's Introduction

grunt-cache-bust

npm version Build Status Dependency Status Join the chat at https://gitter.im/hollandben/grunt-cache-bust

Bust static assets from the cache using content hashing

PLEASE READ

This plugin recently upgraded to v1.0.0!! There was a big change in the way the plugin works. You can read me about the changes in issue #147.

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide.

From the same directory as your project's Gruntfile and package.json, install this plugin with the following command:

npm install grunt-cache-bust --save-dev

Once the plugin has been installed, enabled it inside your Gruntfile.

grunt.loadNpmTasks('grunt-cache-bust');

The "cacheBust" task

Use the cacheBust task for cache busting static files in your application. This allows the assets to have a large expiry time in the browsers cache and will only be forced to use an updated file when the contents of it changes. This is a good practice.

Tell the cacheBust task where your static assets are and the files that reference them and let it work it's magic.

Supported file types

All of them!!

How it works

In your project's Gruntfile, add a new task called cacheBust.

This is the most basic configuration you can have:

cacheBust: {
    taskName: {
        options: {
            assets: ['assets/**']
        },
        src: ['index.html']
    }
}

These are the two mandatory fields you need to supply:

The assets option that is passed to the plugin tells it what types of files you want to hash, i.e. css and js files. You must also provide the location for these files. In the example above, they live in the assets folder.

The src part of the configuration you should have seen before as it's used by pretty much every Grunt plugin. We use this to tell the plugin which files contain references to assets we're going to be adding a hash to. You can use the expand configuration option here as well

To summarise, the above configuration will hash all the files in the assets directory and replace any references to those files in the index.html file.

Options

Summary

// Here is a short summary of the options and some of their 
defaults. Extra details are below.
{
    algorithm: 'md5',                             // Algorithm used for hashing files
    assets: ['css/*', 'js/*']                     // File patterns for the assets you wish to hash
    baseDir: './',                                // The base directory for all assets
    createCopies: true,                           // Create hashed copies of files
    deleteOriginals: false,                       // Delete the original file after hashing
    encoding: 'utf8',                             // The encoding used when reading/writing files
    hash: '9ef00db36970718e',                     // A user defined hash for every file. Not recommended.
    jsonOutput: false,                            // Output the original => new URLs to a JSON file
    jsonOutputFilename: 'grunt-cache-bust.json',  // The file path and name of the exported JSON. Is relative to baseDir
    length: 16,                                   // The length of the hash value
    separator: '.',                               // The separator between the original file name and hash
    queryString: false                            // Use a query string for cache busting instead of rewriting files
    outputDir: ''                                 // Directory where all hashed assets will be copied. Is relative to baseDir
    clearOutputDir: false,                        // Clear output directory. If outputDir was not set clear will not work
    urlPrefixes: ['http://owncdn.test.com/path']  // Array of Url + Path of own CDNs where hashed files are uploaded to. 
}

options.algorithm

Type: String
Default value: 'md5'

algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha1', 'md5', 'sha256', 'sha512'

options.assets

Type: Array

assets contains the file patterns for where all your assets live. This should point towards all the assets you wish to have busted. It uses the same glob pattern for matching files as Grunt.

options.baseDir

Type: String
Default value: false

When set, cachebust will try to find the assets using the baseDir as base path.

assets: {
    options: {
        baseDir: 'public/',
    },
    files: [{   
        expand: true,
        cwd: 'public/',
        src: ['modules/**/*.html']
    }]
}   

options.urlPrefixes

Type: Array of Strings
Default value: ``

When set, cachebust will try to find the assets with this prefixes, useful for:

  • Asset files uploaded to a separate cdn
  • Asset files which are served out of a deeper path within your deployment

For example:

cacheBust: {
  options: {
    urlPrefixes: ['/dashboard/app/app.min.js']
  }
}

will convert:

<script src="/dashboard/app/app.min.js"></script>   

into

<script src="/dashboard/app/app.min.bce0b589338ff97a.js"></script>   

options.createCopies

Type: Boolean
Default value: true

When set to false, cachebust will not create hashed copies of the files. Useful if you use server rewrites to serve your files.

options.deleteOriginals

Type: Boolean
Default value: false

When set, cachebust will delete the original versions of the files that have been hashed. For example, style.css will be deleted after being copied to style.dcf1d324cb50a1f9.css.

options.encoding

Type: String
Default value: 'utf8'

The encoding of the file contents.

options.hash

Type: String

A user defined value to be used as the hash value for all files. For a more beneficial caching strategy, it's advised not to supply a hash value for all files.

options.jsonOutput

Type: Boolean
Default value: false

When set as true, cachbust will create a json file with an object inside that contains key value pairs of the original file name, and the renamed md5 hash name for each file.

Output format looks like this:

{
  '/scripts/app.js' : '/scripts/app.23e6f7ac5623e96f.js',
  '/scripts/vendor.js': '/scripts/vendor.h421fwaj124bfaf5.js'
}

options.jsonOutputFilename

Type: String
Default value: grunt-cache-bust.json

The file path and name of the exported JSON. It is exported relative to baseDir.

options.length

Type: Number
Default value: 16

The number of characters of the file content hash to prefix the file name with.

options.separator

Type: String
Default value: .

The separator between the original file name and hash.

options.queryString

Type: Boolean
Default value: false

Use a query string for cache busting instead of rewriting files.

Usage Examples

The most basic setup

cacheBust: {
    taskName: {
        options: {
            assets: ['assets/**']
        },
        src: ['index.html']
    }
}

Bust using a query string instead of rewriting files

cacheBust: {
    taskName: {
        options: {
            assets: ['assets/**'],
            queryString: true
        },
        src: ['index.html']
    }
}

Bust all assets and update references in all templates and assets

cacheBust: {
    options: {
        assets: ['assets/**/*'],
        baseDir: './public/'
    },
    taskName: {
        files: [{   
            expand: true,
            cwd: 'public/',
            src: ['templates/**/*.html', 'assets/**/*']
        }]
    }
}

Inherited options for multiple tasks

cacheBust: {
    options: {
        assets: ['assets/**'],
        baseDir: './public/'
    },
    staging: {
        options: {
            jsonOutput: true
        },
        src: ['index.html']
    },
    production: {
        options: {
            jsonOutput: false
        },
        src: ['index.html']
    }
}

License

MIT ยฉ Ben Holland

grunt-cache-bust's People

Contributors

angelix avatar ashubham avatar benhoiiand avatar brad avatar brendannee avatar charwking avatar danielcgold avatar denar90 avatar designfrontier avatar fanweixiao avatar fiznool avatar iq-dot avatar johny-gog avatar kenjdavidson avatar kreegr avatar lietzi avatar lnfnunes avatar mynameiscoffey avatar plpeeters avatar richardhinkamp avatar robianmcd avatar ronnyo avatar scottwakefield avatar steve-jansen avatar vasudevan-p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-cache-bust's Issues

Incorrect asset path references

If you have pages that reference an asset with different paths (e.g. relative paths) then the cached reference will be wrong.

Example

Page 1 โ€” /example.html

<script src="./js/script.js"></script>

Page 2 โ€” /foo/example.html

<script src="../js/script.js"></script>

Page 3 โ€” /foo/bar/example.html

<script src="../../js/script.js"></script>

Unexpected Result โ€” Cached result is used in all examples above.

<script src="./js/script.js"></script>

The Regex in L114 doesn't work as expected

'<!โ€“[if lte IE 8]><script type="text/javascript" src="/lib/respond.js"></script><![endif]โ€“>'
  .replace(/\[.*\]>|<!\[endif\]/g, '')

we expect it out put <script type="text/javascript" src="/lib/respond.js"></script>, but in fact, it will output <!โ€“<script type="text/javascript" src="/lib/respond.js"></script>โ€“>

I think the regex should be /<!-\[.*\]>|<!\[endif\]->/g

Media query rules are ignored

The task loops over css rules and declaration for each rule. For media queries the rule is of type "media" and has actual rules under "rules" attribute.

Paths inside a <script type="text/template"> are ignored

When trying to parse html with some markup inside a script tag with alternative type, all that markup isn't parsed and busted.

<img src="welcome.png"> <!-- This will get busted -->
<script type="text/template" id="user-template">
    <img src="default-avatar.png"> <!-- this won't -->
</script>

I believe it would be very helpful to identify script tags with one of the common types used for templating, and parse the markup inside them as usual.

My workaround right now is using some other tag in the source (say xscript) and then replacing it after cacheBust is done.

Switch to a stream HTML parser?

Would it be better to switch to a stream HTML parser and detecting elements and attributes via this? Much simpler to maintain and more reliable than Regex for finding strings to apply busting to.

Something like htmlparser2 would work well for this.

baseDir does not appear to be applied consistently

Ben, first of all, thanks so much for a great plugin! Much better than the other cache-bust plugins I have found.

I'm having trouble getting baseDir to work. None of the assets in the css file are being found. Here's the setup:

  • current dir contains Gruntfile.js
  • dist/ folder (subdir of current) contains all the public content ready to be cache busted. Everything in that folder is relative to that folder (it basically just gets copied to an html folder on a web server). All filenames are relative to index.html and none are absolute (i.e. the whole thing would work from the root of a domain or from a subdir of a domain).

Gruntfile.js

    options: {
        encoding: 'utf8',
        algorithm: 'sha256',
        length: 16,
        baseDir: "dist/",
        jsonOutput: 'rename-cachebuster-map.json',
        deleteOriginals: true,
        enableUrlFragmentHint: true,
    },
    assets: {
        files: [{
            src: [
                  'dist/js/combined.js',
                  'dist/index.html',
                  'dist/css/combined*.css',
                  ]
        }]
    },

If I don't specify dist/ in front of the src files it doesn't find them.
However, the stuff in the css file is not found, e.g. lots of messages like this while processing css:
>> Static asset "images\bg-video.jpg" skipped because it wasn't found.

And the json output:

{
  "dist\\images\\twitter-share.png": "images\/twitter-share.b60dd3dc7e98c7ca.png",
  "dist\\images\\facebook-share.png": "images\/facebook-share.74bcb41d47f3adb0.png",
  "dist\\faq.html": "faq.9cc576831abdd69a.html",
  "dist\\team.html": "team.9b8d5c53ac8c7bd0.html",
  "dist\\js\\combined.js": "js\/combined.740066ba6ac91af5.js",
  "dist\\css\\combined.css": "css\/combined.32469c2f0ebe0f31.css",
  etc.
}

Note the dist/ for the original and missing for the busted. Also note the mixing of forward slashes and backslashes (but I don't think that's the issue).

It would also be nice if the baseDir were auto-applied in front of the asset filenames (so it did not need to be repeated) and did not appear at all in the map json (because it doesn't relate to the distribution package at all). In other words, just prepend baseDir to all file accesses but otherwise don't use it anywhere. Does that make sense?

Is my config broken or have I run into a use case that needs a little more debugging?

Thanks for any tips!
Mike

Cache busting font assets through src property

https://github.com/stackptr/grunt-cache-bust/blob/master/tasks/cachebust.js#L105

This block indicates that the only assets busted in CSS files are those referenced via the background and content properties.

In a given project I have a LESS file referencing font assets that is then compiled to a CSS file using the src property. As such, when the cache-bust task is run on this file, these assets are left intact.

Relatively simple fix, I wanted to check if there was a rationale behind this or if it was possibly a quirk of the LESS parser. Will send PR shortly.

Support for srcset

srcset was implemented in Chrome v35 and is now out in the wild. Could we also allow cache busting on srcset attrs?

Documentation is confusing

assets: {
    files: [{
        src: ['index.html']
    }]
  }

and then you have only

 files: [{
        src: ['index.html']
    }]

... without assets, and if I use without assests I get this issue Warning: Object # has no method 'indexOf'๏ฟฝ Use --force to continue.

Files are re-busted when separate tasks are run

If you run two different cacheBust tasks that both parsed a html file with the same assets, then those assets (and in turn references) would be re-busted without the removal of the previous bust.

Serious tidy up!!

This repo is getting properly messy. List of things to get done:

  • Make sure all files adhere to the settings in .editorconfig - #109
  • Better documentation - there are a lot of settings and a shorter snapshot of them would be better
  • Correspond each cacheBust test in the Gruntfile.js file with each test folder - #110
  • Create a folder for each set of tests with it's assets inside. Will keep them better contained - #110
  • Reduce the size of the assets used so they take up less space, i.e. smaller images - #116

Add support for framework-specific URL syntax (or ASP.NET virtual URLs) when using URL fragment?

This one is a bit of a judgment call, but here's my issue.

I have an ASP.NET MVC application where I'm cachebusting view templates (.cshtml files) that contain links to resources. Virtual URLs (application root-specific URLs, for example if the app is being served up from a subfolder) take the following syntax in ASP.NET's Razor engine:

<script src='@Url.Content("~/Contents/Scripts/jQuery.js#grunt-cache-bust")'></script>

This leads to errors when I run the cachebust task--it can't find a folder named "~". I've managed to work around the issue by changing the syntax to this:

<script src='@Url.Content("~/" + "Contents/Scripts/jQuery.js#grunt-cache-bust")'></script>

so grunt-cache-bust only tries to bust the second half, which gives it a cwd-relative path to bust.

If there was some way to keep from having to write the URLs this way it would be appreciated.

bustOnly Option

Not sure if you'd be interested in this - but I've just implemented a 'bustOnly' option - which updates the reference URLs with the hash of the assets, but does NOT rename the actual files. This works in conjunction with the following server rewrite rules:

#Apache
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.+)\.([0-9a-f]{16})\.(js|css|png|jpg|gif)$ $1.$3 [L]

#Nginx
rewrite '^/(.+)\.([0-9a-f]{16})\.(js|css|png|jpg|gif)$' /$1.$3 last;

The updated repo is here... https://github.com/58bits/grunt-cache-bust

I could submit a pull request if you like the idea.

Refactor!!!!!

This task is now getting very large with a mix of domains, Need to break this up so that the task can be run via the command line and a grunt/gulp wrapper provided.

Also, the test file needs to be broken up so that it's a lot better. Probably move to use Mocha or Jasmine

JSON output file is the direct path, not the relative path

Returning this:

{
    "web/dist/main.js": "web/dist/main.5a2b562d4a2a8c76.js"
}

The output file is doing it's job correctly by returning the path to the files, but it's also replacing already cached files with the base url prepended, i.e.

"web/dist/main.5a2b562d4a2a8c76.js"

not

"/dist/main.5a2b562d4a2a8c76.js"

Can the script work with relative paths?

Here is my issue, in my JSP file where I need to add the cache busting - the JS includes are pointing to the relative path:

<script src="/include/js/lib/jquery/jquery-1.9.1.min.js" type="text/javascript"></script> <script src="/include/js/plugins/jquery-migrate-1.2.1.min.js"></script>

But the script will only work if I put in the full absolute path:

<script src="../../../include/js/lib/jquery/jquery-1.9.1.min.js" type="text/javascript"></script> <script src="../../../include/js/plugins/jquery-migrate-1.2.1.min.js"></script>

Is there any way around this?

Feature request: Cachebusting assets referenced in XML file

Windows 8.1 and IE 11 rely on tile pictures (aka favicons) specified in an XML file called browserconfig.xml that sits at a website's root. We therefore need to cachebust assets referenced in XML. (Thanks, Microsoft!)

I looked through the code and this functionality doesn't appear to exist -- please consider this a feature request.

If you'd like to take a crack at implementing asset path scraping from XML, here's an example browserconfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
  <msapplication>
    <tile>
      <square70x70logo src="/mstile-70x70.png"/>
      <square150x150logo src="/mstile-150x150.png"/>
      <square310x310logo src="/mstile-310x310.png"/>
      <wide310x150logo src="/mstile-310x150.png"/>
      <TileColor>#2b5797</TileColor>
    </tile>
  </msapplication>
</browserconfig>

Images in CSS

Could you add in the ability to bust images in CSS, so url(image.png) format?

Thanks!

Cache busting too aggressive

If a reference to a particular asset exists in different .html pages then each reference to that asset gets a different hash for busting it and then the browser can't re-use the cache for the asset across different pages.

For example, if every html page has an <img src="logo.png" />, each of those will have a different hash and therefore the browser has to GET logo.png for each page that loads.

It would be better if the same hash could be generated for the same static asset that appears in different files.

Paths inside content: url(...) are ignored

The task catches background and background-image rules fine, but images referenced from content rules (of pseudo elements) are skipped, unless you add the #grunt-cache-bust flag of course.

Feature Requets

Is it possible to add the feature of removing the old hashed file after a new one is created? Also, can you add a configuration option to select what you want hashed: .jpg, .png, .js, .css? You may not want to version images automatically.

Add a filter for urlFragmentHint

I'm working with a codebase where I'm running grunt-cache-bust with enableUrlFragmentHint enabled, and some of my #grunt-cache-bust paths reference items on the server, but the server is configured to rewrite URLs. When grunt-cache-bust processes these files, the un-rewritten URLs don't map up with the filesystem, and there's no way to apply filters to make them map. It would be nice to be able to provide a filters object that will be applied to those paths in the same way we can apply filter functions to scripts, CSS, etc.

Not Detecting #grunt-cache-bust?

I've just run grunt cacheBust with the following:

cacheBust: {
      options: {
        encoding: 'utf8',
        algorithm: 'md5',
        length: 16,
        baseDir: 'public/'
      },
      assets: {
        files: [{
          src: ['app/templates/layout.html.twig']
        }]
      }
    },

And it worked - with all of the src urls in the template file cache busted.

 <script src="scripts/jquery-2.1.1.min.e40ec2161fe79931.js"></script>
    <script src="scripts/vendor/scrollup/jquery.scrollUp.min.64a49deb6e8845cd.js"></script>
    <script src="scripts/jquery.detect_swipe.098346a63b3bade9.js"></script>
    <script src="scripts/vendor/spin/spin.4e6303d1ec25fb49.js"></script>
    <script src="scripts/storyserver-core.2240049c27ad2328.js"></script>
    <script src="scripts/storyserver-cards.b438182477a3c240.js#grunt-cache-bust"></script>

However, I was under the impression that only the last script - with #grunt-cache-bust appended, would be cache busted, and that the others would be left alone?

Am I missing an option?

How to override baseDir or use multiple baseDir per asset? Update: PR added

Hi Guys,

I have an issue which I don't know if grunt-cache-bust can do or not.

I have some HTML files which reside in /public references assets relatively within /public. So the assets themselves do not have the '/public' as part of their URL. So I set the baseDir to /public.

However I also have a javascript file that handles the loading of other JS files which resides outside of /public and so it references files like this '/public/x/y/z.js'

How do I do this? if I set baseDir to /public it fails on the javascript file.

If I set the baseDir to outside of /public then the html files fail.

Can I know somehow set the baseDir per asset?

I.e like this:

           assets: {
                files: [
                    {
                        expand: true,
                        cwd: 'public/',
                        baseDir: 'public/',
                        src: ['modules/**/*.html']
                    },
                    {
                        cwd: './',
                        baseDir: '/',
                        src: ['config/config.js']
                    }
                ]
            }

Filter for <use> elements doesn't work

I'm using a SVG sprite to show icons. They are included in the markup like this:

<svg>
  <use xlink:href="/images/sprite.svg#icon-arrow" />
</svg>

To cachebust the references to sprite.svg, I configured grunt-cache-bust by following the default filter examples:

cacheBust: {
  options: {
    ...
    filters: {
      'use': function() { 
        return this.attribs['xlink:href'].split('#')[0]; 
      }
    }
  },
  ...
}

grunt-cache-bust correctly goes through my markup and busts some other stuff like JS scripts, but the <use> tags are left untouched. No errors (like files not being found) are reported either.

Did I make a mistake when defining my custom filter or is it something with grunt-cache-bust?

Bust assets in comments or conditional statements

Example:

<!doctype html>
<html>
<head>
    <title>This is a test page</title>

    <!--[if lte IE 8]> <link rel="stylesheet" href="assets/standard.css" /> <![endif]-->
</head>
<body>

    <!-- <script src="assets/standard.js"></script> -->

</body>
</html>

Filters Error

I get a Object does not have attr error when using

filters: {
        'script' : [
            function() { return this.attr('data-main');} // for requirejs mains.js
            function() { return this.attr('src'); }, // keep default 'src' mapper
        ]
      }

looking at the source, should it be?

filters: {
        'script' : [
            function() { return this.attribs('data-main');} // for requirejs mains.js
            function() { return this.attribs('src'); }, // keep default 'src' mapper
        ]
      }

Ignore patterns not working for me

javscript
options:{
ignorePatterns:['mappin.png','mappin-selected.png']
}


still I get mangled names for my images that contain mappin in their name

Make cacheBust a multi task/remove hash from busted url

Two feature requests:

-Allow multiple configurations/parameters to support different scripts for different environments. For example qa scripts are not concatenated but production scripts are concatenated into one file. Cachebusting QA is sometimes a necessity. The current workaround is to add all of the files into the configuration and let it warn when files are missing.

-Add an option for removing the grunt-cache-bust URL fragment so it doesn't show up in the links. This would be best suited for a prod-specific configuration. The current workaround is an additional grunt task to scan through the files and delete all instances of "#grunt-cache-bust".

Hash prepending not updating

    cachebust: {
      options: {
        encoding: 'utf8',
        algorithm: 'md5',
        length: 8,
      },
      assets: {
        files: [{
          src: [
            'src/t3/views/layouts/application.ctp',
          ]
        }]
      }
    }

After the first intitial cachebust

<script src="/js/build/t3/application.min.js?5c2df7d1"></script>

The hash gets applied correctly on the first grunt cachebust but on any busts after the first it appears to be prepending a new hash on top of the other

<script src="/js/build/t3/application.min.js?5c2df7d1?b726fb86"></script>

I expect this to remove the first hash entirely and add the new new hash.

Re-busting broken in 0.3.3+?

After upgrading to 0.3.3+, my markup is not changing if it already has busted assets and those assets need updating. This is working correctly in 0.3.2.

Expected and working in 0.3.2: (obvious but wanted to make it easy to see)

what html
before <link href="/css/application_8d527a1c6f21b462.css" rel="stylesheet">
after <link href="/css/application_27b1987971e4ceae.css" rel="stylesheet">

0.3.3+:

what html
before <link href="/css/application_8d527a1c6f21b462.css" rel="stylesheet">
after (no change) <link href="/css/application_8d527a1c6f21b462.css" rel="stylesheet">

the new file is being created with the new hash, it's just the markup that is not changing. If the file is not already busted, the markup is changed as expected.

0.3.3+:

what html
before <link href="/css/application.css" rel="stylesheet">
after <link href="/css/application_8d527a1c6f21b462.css" rel="stylesheet">

Not clear what the baseDir option does

Perhaps this is the same issue as what's being talked about in #25, but I read the thread and wasn't completely sure.

I'm using a highly modified Jekyll-based setup. My directory structure is something like this:

/src/assets/stylesheets
/src/assets/javascripts
/jekyll/index.markdown
/jekyll/assets/...
/jekyll/_site # compiled public site is here

I want to have my deployment run this task only on the compiled output in jekyll/_site when the site is in production, but it looks like I don't have a way to do that in the options. I set baseDir but had a bit of disaster when the task modified source files further up the directory tree.

When I saw a baseDir option I didn't realize any files above it would be touched.

Some requests + bug

  1. Add an option not to check for file existence (I have a case in my project where I actually need that)
  2. Don't check tag type. Take everything that has a src or a href, e.g:
$('[src]').filter(checkIfRemoteFile).map(function() { return this.attr('src'); });
$('[href]').filter(checkIfRemoteFile).map(function() { return this.attr('href'); });
  1. If you implement the second request then this is obsolete, but if you won't then this should be fixed:
$('script') // should be $('script[src]'), since then embedded script tags are counted in

Issue with some fonts and images in css

Hi

First of all, thanks for the great plugin!

I'm not sure, but it seems to be some issue with parsing of font-face declaration and images

For instance, we have following task:

module.exports = ->
  @config 'cacheBust',
    build:
      options:
        algorithm: 'md5'
        deleteOriginals: true
        baseDir: '<%= path.build.root %>'
      files: [
        src: [
          '<%= path.build.root %>/{,**/}*.html',
          '<%= path.build.root %>/{,**/}*.css'
        ]
      ]

following css:

@font-face {
  font-family:icons;
  src:url(/assets/fonts/icons.eot);
  src:url(/assets/fonts/icons.eot#iefix) format(embedded-opentype),
      url(/assets/fonts/icons.woff) format(woff),
      url(/assets/fonts/icons.ttf) format(truetype);
  font-weight:400;
  font-style:normal;
}

.sprite {
  background:url(/assets/sprites/sprite.png) no-repeat;
}

This will produce:

Fonts file-names like those:

icons.f1d05013cb3afab0.eot
icons.ttf
icons.woff

Spirte file-name like that:

sprite.dfa1acde53d18b33.png

And following css:

@font-face {
  font-family:icons;
  src:url(/assets/fonts/icons.f1d05013cb3afab0.eot);
  src:url(/assets/fonts/icons.f1d05013cb3afab0.eot#iefix) format(embedded-opentype),
      url(/assets/fonts/icons.woff) format(woff),
      url(/assets/fonts/icons.ttf) format(truetype);
  font-weight:400;
  font-style:normal;
}

.sprite {
  background:url(/assets/sprites/sprite.png) no-repeat;
}

Notice that ttf and woff didn't receive proper names. It seems that it somehow related to the fact that they are defined in @font-face declaration by using comma.

Also you can notice that sprite url in CSS declaration wasn't updated for some reason.

If we'll call css src before html, like that:

module.exports = ->
  @config 'cacheBust',
    build:
      options:
        # @todo Enable length option when PR with fix will be merged
        # length: 6
        algorithm: 'md5'
        deleteOriginals: true
        baseDir: '<%= path.build.root %>'
      files: [
        src: [
          '<%= path.build.root %>/{,**/}*.css',
          '<%= path.build.root %>/{,**/}*.html'
        ]
      ]

it will fix issue with not updated url in .sprite selector for some reason, but it's seems to be like wrong behavior โ€” shouldn't result be same, regardless of the order?

It, of course, also doesn't fix issue with @font-face declaration.

Thanks in advance

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.