# Version compatibility
New gadget and the web app features are not supported in old versions of Feishu. Therefore, version compatibility needs to be considered when new features are used.

You can make your code backwards compatible in the following ways:

## Gadget compatibility
### 1. Compare version numbers
You can compare the version numbers of Feishu and the base library of the gadget to address compatibility issues.
**Notice**：- **Feishu version number**: indicates the version of Feishu, in the format of Major.Minor.Patch (major version, minor version, patch version), such as `5.0.2`. It is the same as the version number shown in the app store. You can get the version number through the `version` field returned by [tt.getSystemInfo()](https://open.feishu.cn/document/uYjL24iN/uQjNx4CN2EjL0YTM).
- **Gadget base library version number**: indicates the version of the base library of the gadget, in the format of Major.subMajor.Minor.Patch (major version, sub-major version, client-side version, patch version), such as `1.9.55.2`. It is updated with the Feishu version number. You can get the base library version number through the `SDKVersion` field returned by [tt.getSystemInfo()](https://open.feishu.cn/document/uYjL24iN/uQjNx4CN2EjL0YTM).

The lowest **Feishu version number** required by each feature is in the description page for the component and API.

You can obtain the Feishu version number of the current gadget by calling [tt.getSystemInfo()](https://open.feishu.cn/document/uYjL24iN/uQjNx4CN2EjL0YTM) or [tt.getSystemInfoSync()](https://open.feishu.cn/document/uYjL24iN/uUjNx4SN2EjL1YTM), and run compatible code if the version is too low.

Comparison of version numbers applies to all cases. In some scenarios, the following method also works.

**Note: Do not compare the version numbers with a simple string comparison.**

Refer to the following code for version number comparison:

```js
function compareVersion(v1, v2) {
  v1 = v1.split('.')
  v2 = v2.split('.')
  const len = Math.max(v1.length, v2.length)

while (v1.length < len) {
    v1.push('0')
  }
  while (v2.length < len) {
    v2.push('0')
  }

for (let i = 0; i < len; i++) {
    const num1 = parseInt(v1[i])
    const num2 = parseInt(v2[i])

if (num1 > num2) {
      return 1
    } else if (num1 < num2) {
      return -1
    }
  }

return 0
}

compareVersion('1.11.0', '1.9.9') // 1
```

```js
const version = tt.getSystemInfoSync().version

if (compareVersion(version, '3.38') >= 0) {
  let adapter = tt.getNFCAdapter()
  // TODO
} else {
  // To guide users to use the latest Feishu for your gadget, pop up a prompt like this:
  tt.showModal({
    title: 'prompt',
    content: 'Your Feishu version is too old to support this feature. Upgrade to the latest version and try again.'
  })
}
```

### 2. Check API existence
For a new API, you can determine whether the base library version supports it by checking whether the API exists. For example:

```js
if (tt.getNFCAdapter) {
  let adapter = tt.getNFCAdapter()
} else {
  // To guide users to use the latest Feishu for your gadget, pop up a prompt like this:
  tt.showModal({
    title: 'prompt',
    content: 'Your Feishu version is too old to support this feature. Upgrade to the latest version and try again.'
  })
}
```

## Web app compatibility
The `H5SDK` version and the Feishu version need to be compared for web apps.
**Notice**：**H5SDK version number**: indicates the SDK version of the web app, in the format of Major.Minor.Patch (major version, minor version, patch version), such as `1.5.11`. You can get the version number through the src attribute in the [Web app development](https://open.feishu.cn/document/uYjL24iN/uMTMuMTMuMTM/introduction).

The SDK version number in the link below is `1.5.11`.

```https://lf1-cdn-tos.bytegoofy.com/goofy/ee/lark/h5jssdk/lark/js_sdk/h5-js-sdk-1.5.11.js```
* **Feishu version** can be obtained by using the UA (navigator.userAgent) in the web app or through the [getSystemInfo](https://open.feishu.cn/document/uYjL24iN/uQjNx4CN2EjL0YTM) API in [JS API overview](https://open.feishu.cn/document/uYjL24iN/uMTMuMTMuMTM/).
* The H5SDK version is the version included in the link. We recommend you to always use [the latest H5SDK version](https://open.feishu.cn/document/uYjL24iN/uMTMuMTMuMTM/introduction) to ensure that the newest features are available.

