4

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?

4

3 回答 3

12

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.

于 2012-08-08T18:58:54.400 回答
1

缩小和base64编码。这是关于 base64 encoding 的问题。请注意,您所做的只是让查看代码的过程变得悲惨,仅此而已。

在线编码器/解码器

于 2012-08-08T19:07:20.537 回答
1

您始终可以缩小 JavaScript 文件,以使其他人更难阅读或修改它。

例如: http: //www.minifyjavascript.com/

你也可以用 CSS 做同样的事情。

http://developer.yahoo.com/yui/compressor/ (它可以做 JavaScript 和 CSS)

还有其他站点提供了一种缩小文件的方法,但无法从客户端完全隐藏它。

于 2012-08-08T19:02:49.093 回答