CDN Caching Control in SuiteScript Server Scripts

Set CDN caching duration in SuiteScript server scripts to optimize performance and control resource loading.

·2 min read·View Oracle Docs

CDN caching plays a critical role in enhancing performance by temporarily storing resources closer to the user, thereby reducing load times. In SuiteScript, developers can leverage CDN caching to specify how long resources should be cached, ensuring that the latest versions are available when needed. This capability is particularly useful in scenarios where data freshness needs to be balanced with performance requirements.

Method Description

The method sets the CDN caching duration for a given resource. This means developers can instruct how long the content should be stored before it is considered stale and needs to be fetched again from the server.

Returns

This method returns void, indicating it does not return any value upon execution.

Supported Script Types

  • Server scripts: This method is exclusively available for use in server-side scripts.

Governance

This method does not require specific governance limits, making it straightforward to implement without performance concerns over quota limits.

Module

The method is part of the N/http Module used for handling HTTP requests and responses in SuiteScript.

Parent Object

It operates as a member of the http.ServerResponse object, which encapsulates the response object for server-side HTTP requests.

Parameters

The method expects the following parameters encapsulated in a JavaScript object:

ParameterTypeRequired / OptionalDescription
options.typeenumRequiredSpecifies the value for the caching duration. Use http.CacheDuration to assign this value. When set to UNIQUE with a Suitelet, the resource never caches and is always executed fresh on request.

Error Handling

It is important to handle errors when using this method. The following error code may be thrown:

  • Error Code: SSS_MISSING_REQD_ARGUMENT
    • Message: Missing a required argument: {param name}
    • Thrown If: The options.type parameter is not specified.

Example Syntax

Below is an example of how to use this method within a server script, demonstrating its syntax:

suitescript
// Set CDN cache duration for an HTTP response
serverResponse.setCdnCacheable({
type: http.CacheDuration.MAX
});

This example showcases setting the caching duration to the maximum value, ensuring optimal loading performance before the cache expires.

Related Topics

Key Takeaways

  • Set CDN caching duration in SuiteScript for efficient data loading.
  • Exclusively supports server-side scripts.
  • Requires options.type parameter to specify cache duration.
  • Returns no value but performs vital performance optimization.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Does CDN caching control in SuiteScript apply to client scripts?
No, the CDN caching control method is exclusively available for use in server-side scripts.
Is there a governance limit for using the CDN caching control method in SuiteScript?
No, this method does not require specific governance limits, making it easy to implement without concerns over performance quotas.
What parameter is required when using the CDN caching method in SuiteScript?
The `options.type` parameter is required, specifying the caching duration using `http.CacheDuration`. This parameter is crucial and will throw an error if not provided.
How do I handle errors when using the CDN caching control method?
You should handle errors such as `SSS_MISSING_REQD_ARGUMENT`, which is thrown if the `options.type` parameter is not specified.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →