SAPUI5 creating, but not running preload files - sapui5

I have set up the following bootstap, with data-sap-ui-preload set to "auto"
<!-- Bootstrap the UI5 core library -->
<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="auto"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-resourceroots='xxxxxxxxxxx'>
</script>
This creates a Component-preload.js file in all of my 3 separate apps.
Unfortunately, when I run it, the files aren't minified, and I can access the controller etc directly.
Has anyone else came across this issue?

if I understand correctly you are expecting that "data-sap-ui-preload" creates additional files and also minifies the code. Is that correct?
If i read the documentation correctly this is not what this parameter is used for.
If you are looking of ways on how to "minify" your could you should look into GruntJS. There is also a UI5 Grunt task runner that is used by SAP itself.

Related

Bootstraping OpenUI5 from single JS file

OpenUI5 documentation suggests starting work by using a library loaded from CDN:
<script id="sap-ui-bootstrap"
type="text/javascript"
src="https://openui5.hana.ondemand.com/1.42.6/resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize"
data-sap-ui-libs="sap.m,sap.ui.table"></script>
Unfortunately, this approach means load cascading 4 scripts on startup:
sap-ui-core.js
sap/ui/core/library.js (why ?)
sap/m/library.js
sap/ui/table/library.js
Is there way to bundle this four libraries into one script file?
Unfortunately, this approach means load cascading multiple scripts on startup:
The cascading behavior is mostly due to missing an option that tells the framework to load UI5-libraries and other modules asynchronously. In order to fix it, please add the following attribute too:
data-sap-ui-async="true" // available since 1.58.2 --> Replaces preload="async" *
data-sap-ui-preload="async" // for 1.58.1 and below
* Prerequisite: Is Your Application Ready for Asynchronous Loading?
Is there way to bundle these four libraries into one script file?
Yes; with a self-contained build (e.g. ui5 build self-contained --all ), you can reduce the size of your application as well as number of requests by bundling the required modules into a single file sap-ui-custom.js
In the above screenshot, for example, sap-ui-custom.js contains only the required modules from sap.ui.core-, sap.m-, sap.ui.table-, and sap.ui.unified-library, in addition to application related resources such as the controllers, views, etc..
See openui5-sample-app and the UI5 tooling for official documentation.

How to use Material-UI in asp.net mvc project

Is there a way of using Material-UI without having to go through installing all of the dependencies using NodeJS. I would love to use this in an ASP.NET Project but dont know where to begin as per installing dependencies and all of that.
Technically using Material UI without any frontend infrastructure is possible, but it's not recommended.
If you really don't want to use npm and other JS build/bundling tools you can use the UMD distribution of Material UI.
The Getting started (#CDN) page should help.
In short, you can add React, Babel, and Material UI using plain old script tags in your HTML:
<head>
<script
src="https://unpkg.com/react#latest/umd/react.development.js"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/react-dom#latest/umd/react-dom.development.js"></script>
<script
src="https://unpkg.com/#mui/material#latest/umd/material-ui.development.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/babel-standalone#latest/babel.min.js"
crossorigin="anonymous"
></script>
<!-- Fonts to support Material Design -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
<!-- Icons to support Material Design -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
</head>
then write your JS in a <script type="text/babel"> tag:
<script type="text/babel">
const {
Button,
ThemeProvider,
createTheme
} = MaterialUI;
const theme = createTheme();
function App() {
return (
<Button>Hello, world</Button>
);
}
ReactDOM.render(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>,
document.querySelector('#root'),
);
</script>
<div id="root"></div>
See https://github.com/mui/material-ui/tree/master/examples/cdn for a working example.
This solution is great for prototyping, but not suitable for production apps. The primary reason for this is low performance. Browsers must download the whole library (including the parts you don't use in your application) and Babel must compile your React app on the fly.
A much better approach is to have an ASP.NET API application and a separate frontend application using React and Material UI that is built using JS tools.
it's very easy.. Follow the below steps.
Commit all the existing changes to your source control or backup existing code.
delete or comment twitter bootstrap bundles in bundle config.
using NPN .. install material design lite package.
add all the .css and .js references to bundles.
add new bundles you added to the layout page.
Remember to change all the class that uses twitter bootstrap to material design lite.
useful sources:
Learning Material Design
MDL Website

How to load sapui5 resources in the background

In our application we load a number of SAPUI5 libraries.
index.html has the following code to load the SAPUI5 resources
<script src="resources/sap-ui-cachebuster/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-appCacheBuster="./">
</script>
In our web.xml we have mentioned https://sapui5.hana.ondemand.com as the com.sap.ui5.resource.REMOTE_LOCATION to load the resources.
What we are observing is that the application takes a very long time to load for the first time. And network calls give an idea that loading of UI5 resources takes maximum time.
Is there a way we can load the UI5 resources faster? or in the background?
An advice or a code sample will really be helpful here. Thanks.
You can load UI5 resources asynchronously. Use data-sap-ui-preload="async"
<script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-preload="async"
data-sap-ui-appCacheBuster="./">
But you must delay the access to the SAPUI5 APIs by using the attachInitEvent method
var oCore = sap.ui.getCore();
oCore.attachInit(function() {
//do the needful
});
You are trying to load too much at a time :sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m
Try to load only the essential parts and rest of the parts as async method so user can at least see some action before waiting too long:
Sync
<script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons,sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-appCacheBuster="./">
ASYNC
<script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.table,sap.ui.ux3"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-preload="async"
data-sap-ui-appCacheBuster="./">

Is is possible to load .coffee script file to browser and execute?

I am trying to load coffee script inside a sample.coffee file along with the coffee-script.js file and perform some simple operations on the HTML. But i am not able to load the sample.coffee file.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="sample.coffee" type="text/coffeescript"></script>
<script src="coffee-script.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
Here is the coffeescript code inside sample.coffee
message = "Welcome to Coffeescript"
alert message
I referred the blog http://forgivingworm.wordpress.com/2010/09/27/running-coffeescript-in-browser/
I trying to run this in MVC4 project on .cshtml. So I am running under MS world.
I am not sure if this is possible or not? any insight into this would be greatly appreciated.
I am able to solve this issue by using the CoffeeSharp http://tomlokhorst.github.com/CoffeeSharp/ It gives handler for .coffee files also converts the coffeescript to javascript on the browser.
Also I am able to compile the coffeescript to javascript during the build event itself which solves deployment and performance related issues.
I dont think this will work like you tried it.
You will need something like requirejs and the coffeescript loader
at https://github.com/jrburke/require-cs.
However I would strongly discourage this and rather have it compiled before loading into the browser (require.js is encouraged though). You might find grunt.js helpful for "building" your app before deploying.
That html works fine for me. I used the coffee-script.js found here: https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js and my sample.coffee is:
x = ->
alert("hi")
x()
If you open the Javascript console, do you see any errors?

In Gwt where the path of script(appName.gwt.js) which loads gwt app comes from?

I have started Gwt last week. And I was trying to create application without using sample app. So initially i have typed following line in html file(Application Name-loginAppGwt, package- LoginAppGwt)
<script type="text/javascript" language="javascript" src="LoginAppGwt/LoginAppGwt.nocache.js"></script>
but it was not loading the gwt module. When i changed it to
<script type="text/javascript" language="javascript" src="loginAppGwt/loginAppGwt.nocache.js"></script>
It was working fine.
But in one of the application which i have created using sample application of gwt, there was written(application name- testingApp, packagename- test)
<script type="text/javascript" language="javascript" src="testingapp/testingapp.nocache.js"></script>
So , my doubt is where this name comes from like in my application loginAppGwt was correct but in sample application testingapp was correct??
Thanks in advance.
Module name can be manipulated via <module rename-to="newname">. Then the path would be newname/newname.nocache.js
Check if your example had something similar in it's module descriptor.
Update:
Loading of JS scripts is affected by filesystem case-sensitivity because scripts are loaded from files. However, GWT-RPC is handled by servlets and is always case sensitive. This is important because, GWT-RPC urls are prepended with package name which seems to be derived from first part of script name in a host file (I just tested this).
So while the main script would be loaded on case-insensitive filesystems regardless of the script name case, the GWT RPC would only work if package names are equal.