简体   繁体   English

在Node.js中使用JavaScript库

[英]Using JavaScript libraries with Node.js

I've written a small animation using node, express and the TweenJS library 我使用node,express和TweenJS库编写了一个小动画

Published on heroku for you to see here. 在heroku上发布,你可以在这里看到

Currently when you click view source you get the following source. 目前,当您单击查看源时,您将获得以下来源。

Currently all of the javascript is handled client-side and script tags are called in the .jade files 目前所有的javascript都是在客户端处理的,脚本标签在.jade文件中调用

To wrap my head around client side and server side javascript I would like to write this app so that the animation is executed server side. 为了包围客户端和服务器端javascript,我想写这个应用程序,以便动画在服务器端执行。 This should then stop viewers from being able to see the javascript source easily. 这应该会阻止观看者轻松查看javascript源代码。

I have researched 我研究过

module.exports module.exports

and looked at the method of calling 并看着调用的方法

var animation = require('./animation.js'); var animation = require('./ animation.js');

for all of the required js files, but I am still stuck and dont quite get how executing the animation server side is possible. 对于所有必需的js文件,但我仍然卡住,并没有完全了解如何执行动画服务器端是可能的。

Thanks for your time. 谢谢你的时间。

If you code executes server side how will it tell the browser what to display? 如果您的代码执行服务器端,它将如何告诉浏览器显示什么? You could do calculations server side and only send a stream of commands to a server side interpreter I suppose, or generate an animated gif, but at what cost? 你可以做计算服务器端,只发送一个命令流到我想的服务器端解释器,或生成一个动画gif,但代价是什么?

You can minify, with something like the closure compiler or uglifyjs, your code before posting it to the server which would obscure it from casual observation. 在将代码发布到服务器之前,您可以使用闭包编译器或uglifyjs之类的代码来缩小代码,这会使其在偶然观察中变得模糊不清。

I'm afraid it doesn't work that way, you can't simply take a library that usually runs on a browser then expect it to run on node.js to manipulate the browser while your coding is "hidden" from the users. 我担心它不会那样工作,你不能简单地选择一个通常在浏览器上运行的库,然后期望它在node.js上运行,以便在你的编码被用户“隐藏”时操纵浏览器。

Animation is inherently browser-based (access to DOM elements, manipulate their CSS etc) 动画本质上是基于浏览器的(访问DOM元素,操纵他们的CSS等)

You may imagine an animation setup where the calculations are done server side, with messages going from server to the browser to reposition and manipulate the DOM elements, but that's awfully inefficient and too much of a price to pay just to hide your animation code. 您可以想象一个动画设置,其中计算在服务器端完成,消息从服务器传递到浏览器以重新定位和操作DOM元素,但这非常低效且只需隐藏动画代码而付出太多代价。 In the end of the day you can also collect those messages to reverse engineer you animation. 在一天结束时,您还可以收集这些消息以对您的动画进行反向工程。

Maybe client side JS obfuscation (minified & uglified) is a good middle! 也许客户端JS混淆(缩小和uglified)是一个很好的中间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM