Before you begin
Get a copy of the MobileFirst web
SDK, and save the ibm-mfp-web-sdk SDK directory,
or the containing npm_modules directory (if you
downloaded the SDK from npm), to the root directory of your web application.
For information about acquiring a copy of the web SDK, see Acquiring the MobileFirst web SDK.
About this task
To use the APIs that are exported by the
MobileFirst JavaScript web-SDK modules,
you must first load the appropriate modules into your web application:
- ibmmfpf.js - the core web-SDK module, which
exports the JavaScript client-side
API. You must load this module to develop a MobileFirst web
application. This module enables you, for example, to add MobileFirst security
capabilities to your application.
- ibmmfpfanalytics.js (provided in the lib/analytics directory)
- the web-analytics module, which exports the MobileFirst JavaScript web
analytics client-side API. Use this module to add IBM MobileFirst Analytics capabilities
to your web application. For information about MobileFirst Analytics,
see Analytics and Logger.
Note: ibmmfpfanalytics.js depends on ibmmfpf.js,
and must be loaded first (when used).
The
MobileFirst web
SDK supports the common standards for loading JavaScript modules:
- In the Asynchronous Module Definition (AMD) standard, JavaScript modules are loaded asynchronously
from JavaScript code.
You use a module loader, such as RequireJS, to
define your asynchronous modules and their dependencies. Then, you
load the modules from the locations within your JavaScript code where the modules are
needed, without affecting the global namespace. This method is especially
suited for browser environments, and is commonly used in development
of client web applications.
The sample MobileFirst starter
web application (MFPStarterWeb), and the web-application
samples that are available from the Developer
Center, demonstrate how to use RequireJS to load the modules
of the MobileFirst web
SDK asynchronously. For more information about the starter sample
and how to obtain a copy of the sample, see Getting started with a sample MobileFirst application.
- In the CommonJs Modules standard, JavaScript modules are loaded synchronously
by importing the module into the global namespace. In web applications
that use this standard, you import the modules from the <head>
element of your main HTML file. This method is more suited for server
environments, and is commonly used in development of Node.js servers.
Use one of the following alternative procedures, which correspond
to the described load methods, to load the web-SDK modules:
Note: The examples in the procedure assume that your SDK directory
is found in the root of your application directory. If you select
to store it in a different location, adjust the script paths in the
examples. For example, if you downloaded the SDK with npm and saved
the node_modules directory that contains the
SDK directory in the root directory of your application, add node_modules/ before
each SDK module name.
What to do next
Use the initialization method of the core web API to
initialize the SDK, and then develop your application by using the
web SDK APIs. For more information, see Initializing the MobileFirst SDK.