ikkez / f3-assets Goto Github PK
View Code? Open in Web Editor NEWF3 Sugar Assets Plugin
License: GNU General Public License v3.0
F3 Sugar Assets Plugin
License: GNU General Public License v3.0
Plugin works, but there is no output in "compressed" folder. My .ini.:
[ASSETS]
;# if this is false, you need to manually put the group markers like
;# <!-- assets-head --> and <!-- assets-footer --> into your template
auto_include = true
;# be greedy and also fetch all <link>, <script> and <style> tags
greedy = true
;# add some filters to the file type renderer
filter.js = minify,combine
filter.css = minify,combine
;# a writable public path, where filters can put files (relative to webroot)
public_path = compressed/
;# add the mtime to the final resource URI, to aid in asset caching
timestamps = true
And index.php
// Asset manager
$f3->config(__DIR__ . '/../app/config/assets.ini');
$assets = \Assets::instance();
// Execute application
$f3->run();
This might be an odd edge case/work flow, but I'm throwing it out here:
I love using the combine feature of jsdelivr to quickly get a bundle of libs, that you would normally npm install etc.
like
https://cdn.jsdelivr.net/combine/npm/[email protected]/dist/jquery.min.js,npm/[email protected]/dist/js/bootstrap.bundle.min.js,npm/[email protected]/dist/vue.min.js,npm/[email protected]/moment.min.js
now I would consider this bad practice to have that in production, especially if you use jquery@latest
and you load breaking changes without knowing or for privacy reasons.
So I wonder if it makes sense to have a switch in config (external = true|false), that would download the js as it is, rewrites the <script src=""> and serves it from local?
I guess you need also a switch in case you have to load external JS but it shouldn't be cached, so cache="true/false"
sets that.
<F3:asset src="https://cdn.jsdelivr.net/file.js" priority="10" group="head" type="js" cache="true" />
<F3:asset src="https://google.com/analytics.js" priority="10" group="head" type="js" cache="false" />
Does that make sense?
Does this plugin take care of multiple includes of the same files or does it just bundle them twice?
W3C validator says that charset attr is obsolete and shows warning.
Adding tags to the template file does not work if you invoke the template rendering like this:
$template = new Template();
echo $template->render('test.html');
but it does work if you use this:
echo Template::instance()->render('test.html');
According to documentation both should be fine, while the first seems to be favored
http://fatfreeframework.com/views-and-templates#AQuickLookattheF3TemplateLanguage
Es wäre sehr angenehm und konsequent, wenn diese Funktion noch den Parameter $Priority bekommt um die Reihenfolge der Ausgabe bzgl der JS/CSS-Dateien zu bestimmen.
Landet der Content aller addInline-Aufrufe nur in einem Script-Tag z.B. für Javascript/Styles?
(Für Javasript-Schnippsel würde mir ein Skript-Tag for "/body" reichen.)
Dazu steht leider nichts in der Dokumentation.
Ansonsten ist das Plugin wunderbar!
Ich wünsche mir den Integration der folgenden neue Methoden:
/**
* Registers a piece of CSS code.
* @param string $content the CSS code
* @param string $group
*/
public function addCssCode($content,$group='head')
{
$this->addInline($content. "\n",'css',$group);
}
/**
* Registers a piece of javascript code.
* @param string $content the piece of JavaScript code
* @param string $group
*/
public function addJsCode($content,$group='footer')
{
$this->addInline($content ."\n",'js',$group);
}
}
Happy XMas & thanks for your work!
From what I've found, when the f3 UI
variable starts with ../
(../app-ui/
in my case), the files are marked as internal
, but they are not combined into one file and return non accessible paths.
Let's say I have some assets defined as:
$f3->set('UI', '../app-ui');
$assets->addCss('css/style1.css');
$assets->addCss('css/style2.css');
Actual result:
<link rel="stylesheet" type="text/css" href="app-ui/css/style1.css"/>
<link rel="stylesheet" type="text/css" href="app-ui/css/style2.css"/>
Expected result:
<link rel="stylesheet" type="text/css" href="assets/compressed/26awg81rt5es8.css"/>
I can workaround the issue if I change:
https://github.com/ikkez/f3-assets/blob/master/lib/assets.php#L536
- $asset['path']=ltrim($view,'./');
+ $asset['path']=preg_replace('/^\.\//', '', $view,1);
if (is_file($save=$fw->fixslashes($dir.$file)) &&
- is_bool(strpos($save,'../')) &&
preg_match('/\.(css|js)$/i',$file)) {
@ikkez Am I doing something wrong? Thanks.
Hi @ikkez ,
This is a very great plugin!
I just want to proposing any possibility if you will for the next release..
Do you have any feature for single inline scripts or style block not to combine when greedy&handle_inline configs is set true?
Maybe your plugin have some ability to recognize specific attr in scripts or styles html like assets=exclude or combine=false so your plugin bypassing/leaving this inline scripts/styles for combining?
Regards,
Is there template directive available to addInline js? is it possible to implement?
Hi,
I love the idea of your asset management class. However I'm not able to use it right now without your help. I've moved the public www folder from the app folder:
/app
/lib
/www
The f3 assets php class creates some *.css and *.js inside the /www/scripts/combined folder... but they are empty. It seems the class could not access the files in a path outside of the /app folder... If I move them inside the app folder, they files in combined are still empty (and I get the error:
filemtime(): stat failed for ********/www/scripts/test.js
- line 291 )
Could you please help me to support external www folder?
Greetings
"charset" sollte noch unterstützt werden... manche JQuery Plugins haben sonst Ärger mit ältern Browsern ohne Charset-Angabe bei I18n Files.
F3:asset src="plugin/slick/slick.js" charset="UTF-8"
führt zu...
script src="plugin/slick/slick.js" charset="UTF-8"></script
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.