malko / l.js Goto Github PK
View Code? Open in Web Editor NEWanother js loader
License: MIT License
another js loader
License: MIT License
There are a lot of JS loaders, really. But none of them, at least within documentation, addresses a problem I'm eager to solve. That is to use single <script>
line per whole project which inits page-based loading of dependencies.
Let's create a simple project with index, portfolio, and contacts pages.
Microframework will help us with routing:
$app->get('/portfolio/',
function () use ($app) {
$prices = array(
"price_mine" => "90",
"price_rival" => "120"
);
$app->render('portfolio.twig', $prices);
})->name('portfolio');
Template engine will help us with rendering:
{% extends "base.twig" %}
{% block content %}
<p>Aren't you sick and tired to pay {{price_rival}}…</p>.
{% endblock content %}
And the missing part in every page is <script src="/static/init.js"></script>
that works as follows
What's the best way to achieve it?
And how to do that with l.js whether it's possible?
Thank you in advance.
Warm regards from Russia, Alexander.
Hi, @malko
We are having trouble trying to import l.js, the versions are getting messed up because the bower.json is not updated, it would be helpful if you could register l.js in npm in order to clarify the versions.
Greetings, Marlon.
Is it possible to disable a CSS file that was loaded by l.js?
When I load css files in traditional way, without l.js, I currently use this method to disable a specific one:
// To disable a specific css file
document.getElementsByTagName('link')[2].disabled = true
// And, to enable it again
document.getElementsByTagName('link')[2].disabled = false
Is there a way to accomplish this with l.js?
I am embedding the l.min.js script directly into the document by using PHP. The script is stored in an in-memory cache and embedded into the page, then served. At least, that is what I wanted to do. But it seems that gEval
is being called over, and over, and over - untill it causes an error:
Uncaught RangeError: Maximum call stack size exceeded
Could you look into this? Thus far, l.js seems to be the smallest loader that supports "bundles" (i.e. combining a few things into one name)
Kind regards!
The callback is never called. There is a description of a similar issue and a solution in this article : http://jaubourg.net/archive/7/2010
It would be very nice to have a bower.json to be able to install ljs without using the github URL, also to control versions. Also jsdeliver would be a nice option to have.
It seems that after switching to appendElmt instead of gEval there is an scope issue.
Since the var .... appendElmnt is inside an if the variable isn't actually available at the return line (149) thus causing an error in the console>
Uncaught TypeError: appendElmt is not a function
There are several ways to fix it. I just sent a Pull Request with one, but feel free to dismiss it and change it to your own preference.
Hello,
I tried to load multiple css files one by one with a table but the apply doesn't seams to work with a case like thie:
cssUrls = [ "http://../first.css", "http://../second.css" ];
ljs.load.apply(null, cssUrls);
I got this error with Firefox:
TypeError: this.loadcss is not a function
...pply(this,t)}return t.match(/\.css\b/)?this.loadcss(t,e):this.loadjs(t,e)},y={},...
-------------------------------------------^
I have the same kind of error with JavaScript files as urls. Is there an another way to load files one by one from an array ? (v0.1.1)
as describe in issue #14, find and implement a way to allow for better error handling (using a callback instead of a fallback)
Hi,
Incase of any failed resources (dont exist, path incorrect), how can i capture that ? I only see load function.
is there a fail function so i can do something like .load().fail()
I want to use it with aliases method ..
Hi Malko,
I added a retry support to my version of l.js. It basically uses the #id part of the url to give a second url and in case the script fails to load it will retry with the #id url.
For us is helpful since we use a lot of CDNs and some are blocked in internal clients, so this way we can fallback to the local version of the file.
I don't know if you're interested in adding this support. It certainly needs review and I would like to make it optional also (maybe with the same mechanism as checkLoaded?)
I was wondering if l.js should add the script tags with the async attribute.
We use it to load all our stack , specially because of the dependency management we obtain. But since script tags are generated in the head, maybe the async would help speed up the rendering.
Any thoughts?
Hi,
Is it possible to get progress of loaded content ?
I am trying to use pace.js with l.js but it does not work.
I have lots of assets and I need to display progress as just showing busy-spinners dont give information to users on how much is loaded and how much remaining.
Something like
ljs
.addAliases(aliases)
.load('all-assets',function(){ /* your callback here */})
.onProgress( function(value,total ){ /* could display progress here in percentage */})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.