I am implementing the bundling and minification support in MVC4 and it appears as though it is making my javascript files bigger than if they weren't bundled/minified. I am using the latest build available in nuget (pre-release option on). I have the following bundle set up in my RegisterBundles class.
bundles.Add(new ScriptBundle("~/bundles/baseJS").Include(
"~/Scripts/jquery-1.7.1.js",
"~/Scripts/jquery.cookie.js",
"~/Scripts/jquery-ui-1.8.11.js",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.pjax.js",
"~/Scripts/kendo/2012.1.515/js/kendo.all.min.js",
"~/Scripts/jquery.jstree.js",
"~/Scripts/jquery.unobtrusive-ajax.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/RIS.Scripts/PostJson.js"));
And I am loading it into my _Layout.cshtml using
#Scripts.Render("~/bundles/baseJS")
When I add up the bytes received in Fiddler for these scripts in debug mode I get the following
Name Size(bytes)
jquery 98013
jquery cookie 1455
jquery ui 124704
bootstrap 52378
pjax 8138
kendo.all 219751
jstree 55045
unobtrusive-ajax 2492
validate 13323
validate-unobtrusive 5138
postjson 634
Total 581071
And when I run it on my production server I get the following from fiddler for the entire js bundle.
Bytes Received: 999,396
What is going on here? Most of the files are minified to some extent, but it shouldn't almost double the size of my payload.
Additional details-
When I download the js files off my local dev box (fiddler reported size 379kb) and the server (fiddler reported size 999kb) and put them in kdiff they are binary identical. When I look in Chrome's developer tools network tab, the local server downloads 379kb, but the 'Parser' value is 975kb. What is this parser value. Could it be that there is some IIS compression setting that is not set in my server but is on my local IIS server? The only difference I note is the fact that the IIS Express I am running on my dev machine is 8.0 where the server is IIS 7.5.
Most likely what you are seeing here is some of the debug/release 'magic' that comes from the FileExtensionReplacementList.
Let's take jQuery for example. Typically in your scripts folder you will see two copies of each file, i.e. jquery-1.6.2.js and jquery-1.6.2.min.js.
By default optimization will use the min.js version when debug=false, and use the regular jquery-1.6.2.js when debug=true, since typically that makes debugging easier (no bundling and no minification of the bundle).
This file selection 'magic' is controlled via the FileExtensionReplacementList on BundleCollection.
In the next release (RTM), there will be a bit more granularity in this list, as typically developers will want to target when these are should be used, i.e.
list.Add("min", OptimizationMode.WhenEnabled);
list.Add("debug", OptimizationMode.WhenDisabled);
You have the bundling option working, but the minification is done by an BundleTable.EnableOptimizations = true setting and some "transform" options that you've haven't engaged. See CssMinify and JsMinify.
Something along the lines of:
var b1 =new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.*");
b1.Transforms.Add(new JsMinify());
bundles.Add(b1);
- and -
BundleTable.EnableOptimizations = true;
Related
When I disable translation language fallback, then key translations are displayed instead of a particular translation.
However, when running with SSR mode, translation keys are not displayed at all.
I am using the latest version of Spartacus and running server by npm run build:ssr && npm run serve:ssr.
Is there any way to have missing translations displayed in prod mode with enabled SSR?
TLDR;
It's a correct behavior. If you need a custom fallback behavior, please overwrite this method:
https://github.com/SAP/spartacus/blob/4432a2bed0c6cf04aa2ff412792f0e8cb24686a3/projects/core/src/i18n/i18next/i18next-translation.service.ts#L70
Explanation:
SSR runs the production version of the application.
In development mode missing keys are rendered in the HTML (and a warning appears in the console). But in production mode missing keys are rendered in the HTML as a non-breaking space is displayed.
See https://sap.github.io/spartacus-docs/i18n/#fallback-language
There is a javascript library, pre-built and available on npm, that I wish to develop with/debug. In my case, it is openlayers.
In the classic way of requiring a javascript file and wanting to debug, one would just switch the script url from the production version to the debug version, ie:
to
However, when using webpack and then importing via npm:
import openlayers from 'openlayers'
Gets you the production distribution of the library, the same as the ol.js script from above.
On a side note, to stop webpack trying to parse a prebuilt library and throw a warning about that you must include something like this:
// Squash OL whinging
webpackConfig.module.noParse = [
/\/dist\/ol.*\.js/, // openlayers is pre-built
]
Back to the problem at hand: how can I conditionally load a different entry-point for a module prebuilt and imported like this?
Of course, I can do it in a hacky way. By going into the node_modules/openlayers/package.json and switching the browser field from
"browser": "dist/ol.js",
to
"browser": "dist/ol-debug.js",
Is there a way I can request a different entry point via webpack or by using a different import syntax? Do I first have to petition the library maintainers to update the browser field to allow different entry point hints to browsers, according to the spec? https://github.com/defunctzombie/package-browser-field-spec
Thoughts on a more effective way to make this happen? Yearning to be able to programmatically switch loading of the production and debug versions of a library based on env variables.
Webpack has configuration options for replacing a module into a different path: https://webpack.github.io/docs/configuration.html#resolve-alias
This resolves the openlayers import to use the debug version:
webpackConfig.resolve.alias: {
openlayers: 'openlayers/dist/ol-debug.js'
}
In my build system I have a function that takes the environment type and returns the matching webpackConfig. Based on the parameter I include the above snippet or not.
Full code: webpack-multi-config.js
I have two different (gulp-) tasks for development and production. For example the production task: webpackProduction.js
Line 1 imports the config script with production as type.
My build system is based on gulp starter.
After checking out the source from: https://github.com/RallyApps/app-catalog
I attempted to build the Portfolio Item cumulative flow diagram src/apps/charts/rpm/cfd locally using
rally-app-builder build which shows no errors
Launching App-debug.html allows me to input the relevant settings, but once I click 'save', nothing renders and there are no errors logged to the JS console either, making debugging challenging.
I attempted to copy the build output into a custom html app inside rally, which displayed the same behaviour.
Is this a bug with the example app? Or have I missed some crucial configuration step?
EDIT:
Extra info - I tried running via the rally-app-builder to no avail (think it's related to this issue: https://github.com/RallyApps/rally-app-builder/issues/45). I attempted to flatten the structure and the result of that was a cross-origin request error.
Running from file resulted in a 403 for the SDK
Sorry about that- that Rally App Builder issue is definitely the problem you're running into. Just as a test I downloaded the built html output for that app from the app catalog release: https://github.com/RallyApps/app-catalog/releases/download/2.1/2.1.zip
It worked when installed on a custom html app on my dashboard once I edited the app settings and configured a portfolio item.
If you're looking to tweak this app from source you'll probably have to copy all those files referenced in config.json that live in parent directories into the main app directory and fix the paths in config.json. Then you should be able to build and run the app normally using Rally App Builder.
It seems this app was really not designed to be run externally, so I added a little code to ease the issues I ran into:
In PortfolioChartAppBase.js, _loadSavedPortfolioItem function:
scope: this,
fetch: ['Name', 'ObjectID'] //this is new
And I added some default settings as a top level config object in CumulativeFlowChartApp.js (since the code to force into settings mode doesn't seem to work correctly when running externally):
config: {
defaultSettings: {
portfolioItemPicker: '/portfolioitem/feature/52725935318', //insert a valid oid here
startDate: 'actualstartdate',
endDate: 'actualenddate',
chartAggregationType: 'storycount'
}
},
We're evaluating noflo to be executed on an embedded linux box using an simple javascript engine, being an interpreter (no JIT). In our case, the Node.js engine (with embedded V8 engine) might be too resource intensive.
The immediate question is the how to run the noflo runtime in there. Checking out the GitHub repository (https://github.com/noflo/noflo) and using grunt, we have generated the noflo for the browser using grunt build:browser.
As simple example to actually try and run the generated browser/noflo.js file, I used the d8 shell (V8 engine shell) for an isolated Javascript engine outside the Node.js universe, and appended the following code to the noflo.js generated file:
var fbpData = "<some FBP language connections>";
var noflo = require('noflo');
noflo.graph.loadFbp(fbpData, function(graph) {
print("Graph loaded");
});
Then,
d8 noflo.js
on the Linux shell, which reports
rtm.js:9559: TypeError: undefined is not a function
noflo.graph.loadFbp(fbpData, function(graph) {
^
TypeError: undefined is not a function
at rtm.js:9559:13
Without knowing further, leads me to believe that the noflo.js is not self-contained with all core noflo runtime functionality.
What necessary steps are missing here, for me to get noflo library running in an isolated JS engine (V8 is just an example - it could be any engine the is ECMA V5 compliant)
All code examples on the noflo project web site are tailored for Node.js...
PS: I tried as an alternative to build a browser-based noflo from http://noflojs.org/download/, however this always returns "server error".
Best regards
Gunther Strube
The NoFlo-Gnome project contains a browser build of the noflo-runtime-base repository (https://github.com/noflo/noflo-runtime-base) which itself embeds NoFlo.
You might need to add some aliases because the browser build doesn't necessarily fit your engine : https://github.com/noflo/noflo-gnome/blob/master/src/noflo.js#L89
noflo-gnome runs NoFlo in GJS, which is based on Spidermonkey and GLib/GObject.
It has some minimal require() compatibility which allows pulling in NoFlo. There is a checked in build of noflo (+ noflo-runtime-base) in ./src/libs but I did not immediately find how this is created.
If you're considering using a browser build to speed up the startup time, you might also want to look at : https://github.com/djdeath/noflo-iot
At some point I tried to run NoFlo on a board with very slow I/O. It turned out that a single file compacted build of NoFlo (including all the needed components) was significantly faster.
I have gone through this post to run an application in production, but facing an issue.
https://www.ibm.com/developerworks/community/blogs/dhuyvett/entry/the_dojo_library_in_worklight_studio_v6_0?maxresults=15&lang=en
I have created a Worklight 6 hybrid application, listed below is a series of tasks that I performed on it.
I built and deployed the project with the 'Provide Library Resources' checked and I get a list of missing files (a few stated below) in the dojo library requests console and the application works fine.
[[2013-11-14 11:02:48] Application 'SampleBankingApp' requested a
missing resource. Providing library resource:
/dojoLib/toolkit/dojo/dijit/form/DateTextBox.js
[2013-11-14 11:02:48] Application 'SampleBankingApp' requested a missing resource. Providing library resource:
/dojoLib/toolkit/dojo/dijit/form/FilteringSelect.js
[2013-11-14 11:02:48] Application 'SampleBankingApp' requested a missing resource. Providing library resource:
/dojoLib/toolkit/dojo/dijit/Calendar.js]
I copied the missing files into the www folder keeping the folder structure as required, then I built and deployed the app with the 'Provide Library Resources' checked and I still get the same list of missing files in the dojo library requests console and the application also works fine.
Now I built and deployed by unchecking 'Provide Library Resources', when I tried to use the app it doesn't work, and the chrome console (where i use the mobile browser simulator) gives a series of errors like Failed to load resource: the server responded with a status of 404 (Not Found).
Whatever missing files it states in the dojo library requests console is in place inside the www folder, don't know whats going wrong.
I am using Eclipse Juno + Worklight6 + Dojo, any help would really be appreciated.
I think you may be failing on copying the resources to the correct path in the "www" folder.
For example, if you are missing /dojoLib/toolkit/dojo/dijit/form/DateTextBox.js, then you should copy that file into your_project/www/dijit/form