Any way to hide CSS and JavaScript file from the client-side user?

后端 未结 3 2056
梦毁少年i
梦毁少年i 2021-01-13 16:40

Is there any way to hide the CSS and JavaScript file from the client-side user and still embed it in the webpage shown to the user?

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 17:03

    No. CSS and Javascript must be parsable and readable by the browser, therefore a human can get access to the same data.

    It is possible to obscure/compress/minify the javascript, but all that generally does is remove whitespace and rename/shorten variable names. The script is still functional and anyone interesting in how it really works can still figure it out (perhaps by using some tools to reformat it) with a little more time.

    The typical reasons for minification is to reduce the download size of your scripts (speeding up site performance), but it also has the side effect of making the code harder to read by a human. One should not count on minification providing any real protection as the code can be reformatted and still understood by anyone determined to do so.

    If you need to keep something private, keep the logic on the server and don't put it in the client. Clients can access server-based functionality via ajax if need be.

    I've never heard of anyone thinking there was a business reason to protect CSS. It's layout/presentation formatting.

提交回复
热议问题