Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow version numbering of @imported less files so as to enabled browser cache busting when versions change. #1060

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/less/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
try {
contents[href] = data; // Updating top importing parser content cache
new(less.Parser)({
suffix: sheet.suffix | false,
optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')],
mime: sheet.type,
Expand Down
10 changes: 7 additions & 3 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ less.Parser = function Parser(env) {

var imports = this.imports = {
paths: env && env.paths || [], // Search paths, when importing
suffix: env && env.suffix || false, //Suffix to append to imported files when loading to bust browser caches
queue: [], // Files which haven't been imported yet
files: {}, // Holds the imported parse trees
contents: env.contents, // Holds the imported file contents
Expand All @@ -88,7 +89,7 @@ less.Parser = function Parser(env) {
//
// Import a file asynchronously
//
less.Parser.importer(path, this.paths, function (e, root) {
less.Parser.importer(path, this.paths, this.suffix, function (e, root) {
that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue

var imported = path in that.files;
Expand Down Expand Up @@ -1481,15 +1482,18 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
//
// Used by `@import` directives
//
less.Parser.importer = function (path, paths, callback, env) {
less.Parser.importer = function (path, paths, suffix, callback, env) {
if (!/^([a-z-]+:)?\//.test(path) && paths.length > 0) {
path = paths[0] + path;
}
if (suffix) {
path = path + suffix;
}
// We pass `true` as 3rd argument, to force the reload of the import.
// This is so we can get the syntax tree as opposed to just the CSS output,
// as we need this to evaluate the current stylesheet.
// __ Now using the hack of passing a ref to top parser's content cache in the 1st arg. __
loadStyleSheet({ href: path, title: path, type: env.mime, contents: env.contents }, function (e) {
loadStyleSheet({ href: path, title: path, suffix: suffix, type: env.mime, contents: env.contents }, function (e) {
if (e && typeof(env.errback) === "function") {
env.errback.call(null, path, paths, callback, env);
} else {
Expand Down