Skip to content

Commit 4042287

Browse files
committed
new diet
1 parent c825fba commit 4042287

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Optimized [PINF](http://pinf.org/)/[CommonJS](http://commonjs.org/) Loader for J
44
*Status: ALPHA* [![Build Status](https://secure.travis-ci.org/sourcemint/loader-js.png)](http://travis-ci.org/sourcemint/loader-js)
55

66
The `Sourcemint JavaScript Loader` is an optimized *(intended for production use)* **CommonJS package mappings**
7-
based **JavaScript module loader** for the browser in only **1527 bytes** *(minified and zipped)*.
7+
based **JavaScript module loader** for the browser in only **1589 bytes** *(minified and zipped)*.
88

99
* Copyright: 2011 [Christoph Dorn](http://www.christophdorn.com/)
1010
* Code License: [MIT License](http://www.opensource.org/licenses/mit-license.php)

loader.min.js

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loader.min.js.gz

62 Bytes
Binary file not shown.

loader.stripped.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ var sourcemint = null;
3838

3939
// @credit https://github.com/unscriptable/curl/blob/62caf808a8fd358ec782693399670be6806f1845/src/curl.js#L319-360
4040
function loadInBrowser(uri, loadedCallback) {
41-
if (/^\//.test(uri)) {
42-
uri = document.location.protocol + "/" + uri;
43-
}
4441
// See if we are in a web worker.
4542
if (typeof importScripts !== "undefined") {
46-
importScripts(uri);
43+
importScripts(uri.replace(/^\{host\}/, ""));
4744
loadedCallback();
4845
return;
4946
}
47+
if (/^\{host\}\//.test(uri)) {
48+
uri = document.location.protocol + "//" + document.location.host + uri.substring(6);
49+
} else
50+
if (/^\//.test(uri)) {
51+
uri = document.location.protocol + "/" + uri;
52+
}
5053
if (!headTag) {
5154
headTag = document.getElementsByTagName("head")[0];
5255
}
@@ -200,6 +203,13 @@ var sourcemint = null;
200203
{
201204
arguments[2].load = arguments[2].load || sandboxOptions.load;
202205
}
206+
// If the `programIdentifier` (first argument) is relative it is resolved against the URI of the owning sandbox (not the owning page).
207+
if (/^\./.test(arguments[0]))
208+
{
209+
arguments[0] = sandboxIdentifier.replace(/\/[^\/]*$/, "") + "/" + arguments[0];
210+
// HACK: Temporary hack as zombie (https://github.com/assaf/zombie) does not normalize path before sending to server.
211+
arguments[0] = arguments[0].replace(/\/\.\//g, "/");
212+
}
203213
return sourcemint.sandbox.apply(null, arguments);
204214
}
205215
module.require.sandbox.id = sandboxIdentifier;
@@ -335,6 +345,7 @@ var sourcemint = null;
335345
];
336346

337347
// Create a new environment to memoize modules to.
348+
// If relative, the `programIdentifier` is resolved against the URI of the owning page (this is only for the global require).
338349
require.sandbox = function(programIdentifier, loadedCallback, options) {
339350
var sandboxIdentifier = programIdentifier.replace(/\.js$/, "");
340351
return sandboxes[sandboxIdentifier] = Sandbox(sandboxIdentifier, loadedCallback, options || {});

workspace/www/loader.min.js.gz-size

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1527
1+
1589

workspace/www/loader.stripped.js.md5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e389275a24ee47099199fa3d7ffe8112
1+
433f3f017e99370000e16edab13fa698

0 commit comments

Comments
 (0)