Skip to main content
Version: 8.0.3

offline

Learn more about using this API here

The sos.offline API groups together methods for storing and using JS, CSS and font files.

warning

Emulator has certain limitations while handling offline files. Read more here

Methods

addFile()

The addFile() method downloads the specified file and stores it locally.

addFile(file: ISaveFile): Promise<void>;

Example

await sos.offline.addFile({
// Source URL
uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js',
// Unique identifier of the resource
uid: 'jquery-3.7.1.slim.min.js',
// Indicate that the downloaded file is a JavaScript file
type: sos.offline.types.javascript,
// After the file is downloaded, it will be appended to document.body
flags: [sos.offline.flags.append(document.body)],
});

addFiles()

The addFiles() method downloads the specified files and stores them locally. The order in which the files are downloaded and stored is not guaranteed.

addFiles(files: ISaveFile[]): Promise<void[]>;

Example

await sos.offline.addFile([{
uri: 'https://unpkg.com/normalize.css@8.0.1/normalize.css',
uid: 'normalize.css',
type: sos.offline.types.css,
flags: [sos.offline.flags.append(document.head)],
}, {
uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js',
uid: 'jquery-3.7.1.slim.min.js',
type: sos.offline.types.javascript,
flags: [sos.offline.flags.append(document.body)],
}]);

addFilesSync()

The addFilesSync() method downloads the specified files and stores them locally. The order in which the files are downloaded and stored is guaranteed.

addFilesSync(files: ISaveFile[]): Promise<void>;

addFont()

The addFont() method downloads the specified file and stores it locally. You should use this method for loading fonts instead of using addFile(), because it also generates appropriate font-face definition.

addFont(font: IAddFont): Promise<void>;

Params

NameTypeDescription
font.uidstringUnique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters.
font.appendHTMLElementReference to HTMLElement where the generated font-face will resist.
font.fontFamilystringFont family that can be referenced from your CSS.
font.formatsIFontFormatsURI where these formats will be downloaded from.
font.fontStretch (optional)stringAllows you to make text wider or narrower.
font.fontStyle (optional)IFontStyleSpecifies the font style for a text. (Either normal, italic, oblique, initial or inherit)
font.fontWeight (optional)stringSets how thick or thin characters in text should be displayed
font.unicodeRange (optional)stringDefines the range of unicode characters the font supports, default value is "U+0-10FFFF"
font.formatsIFontFormatsDictionary of supported formats with its files