![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Add compressed inline css and scripts to your html, but write them as seperated files.
Add compressed inline css and scripts to your html, but write them as seperated files.
You don't have to worry about accessing the template's local variables. And you can even include a .less
file.
var istatic = require('istatic');
va app = express.createServer();
istatic.enable(app, { compress: false });
The second parameter is optional. The available options are:
Whether to compress the css or js. Default: true
.
Whether to include the file's path in the output. Default: false
.
The root of your inline static files. Default: process.cwd() + '/public/'
.
By default, the contents of your static files are cached in memory forever, until the process dies. You can set the ttl
to a number of seconds, so the cache will be cleared every that much of time.
The charset of your static files. Default: utf-8
.
The options object for compressing a js file. It will be passed to UglifyJS.
Default: undefined
.
The options object for compressing a css file. It will be passed to UglifyCSS.
Default: undefined
.
For css and js options, you can define an js.removals
or css.removals
, to remove some contents (like console.log()
) before compressing. This will make the inline css/script even more smaller, but still keep the maitainability of the code.
By default, there's only removals
for js, and it's an RegExp: /_log\(.+?\)/g
.
Now you can include static files in your template like this:
#{istatic(filename, [options])}
filename
is the path of your static file. If it begins with a '/', the real path will be process.cwd() + filename
. Otherwise, the file will be looked up from the root of your inline static files, as you configured before.
You can set available options above, except for root
and ttl
. A fresh
option is available for you to set this istatic
call always read from file directly.
Be careful, since jade
can not correctly parse curly braces inside a couple of curly braces, don't write:
script
#{istatic('js/my.js', { showPath: (DEBUG ? true : false) })}
Write like this instead:
- istatic_opt = { showPath: (DEBUG ? true : false) }
script
#{istatic('js/my.js', istatic_opt)}
And it's definitely easier to read and maintain, too.
Just get in touch with them in the form you already very familiar with:
#{data.title}
Attention: no matter what templating language you are using, you must always use this syntax in your static files.
And don't put {}
inside the curly braces. This is for performance consideration.
You can even excecute a local funtion just as what you will do in the template:
#{usr.getId('haha...')}
NOTE: These APIs are not for templates.
Return the inlined string of some file.
When passing options
, these options will be saved as default options for any other later istatic
or istatic.enable
calls.
But when you call istatic(filename, options)
in a template, the options will not be save as default options. And APIs below is not suitable for an inside template call, too.
To enable the istatic
helper for an express app
.
Set default options for istatic.enable
and istatic.inline
. This can be implictly done by call istatic(filename, [forceReload, options])
and pass the options
object.
Uglify some css string. Options are passed to UglifyCSS.
Uglify some js string. Options are passed to UglifyJS.
var express = require('express');
var istatic = require('istatic');
var app1 = express.createServer();
var app2 = express.createServer();
istatic.default({ compress: false }).enable(app1).enable(app2);
var compressed_css = istatic.uglify.css('.class1 { font: Arial; }');
var compressed_js = istatic.uglify.js('// some javascript codes..');
var str_pinyin_js = istatic('/utils/pinyin.js');
Visit 大声看法 for a live example.
FAQs
Add compressed inline css and scripts to your html, but write them as seperated files.
The npm package istatic receives a total of 14 weekly downloads. As such, istatic popularity was classified as not popular.
We found that istatic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.