How do front-end .js files separate front-end and front-end give parameters

separate the front and rear ends and separate the .html .css .js. In the background, node and egg framework
are put on the cdn to speed up access, but the disadvantage is how to obtain the parameters?
if you use a template to render ctx.render in view ("",.) Of course, parameters can be obtained. But this virtually increases the request pressure on the back end.


you may want js to get the url parameter. If you truncate the string directly, you can get the parameter.

const getQueryString = paramKey => {
    let url = window.location.href.split('?')[1] || ''
    let params = {}

    url = url.replace(/-sharp.*$/, '').split('&')

    for (let i = 0; i < url.length; iPP) {
        let num = url[i].indexOf('=')
        if (num > 0) {
            let key = decodeURIComponent(url[i].substring(0, num))
            let val = url[i].substr(num + 1) || ''
            try {
                val = decodeURIComponent(val)
            } catch (ex) { }
            params[key] = val
        }
    }
    return params[paramKey]
}

but in fact, it is easier for the backend to do this. The backend is used to do this. If you can't do this, what else can you do

Menu