我正在使用django版本1.82和django-pipeline。我通过名称从html调用特定的javascript函数。
<form class="navbar-form navbar-right vcenter"
action="javascript:search();" role="search" id='searchform'>
不幸的是,在压缩的js文件中,函数的名称已更改,因此前端功能不起作用。如何为该函数维护相同的名称,或者如何在html中更改对js函数的引用?
我已经安装了yuglify,我使用的设置是
PIPELINE_CSS = {
'allstyles': {
'source_filenames': (
'css/application.css',
'feedback/css/feedback-form.css',
),
'output_filename': 'css/nifty.css',
'extra_context': {
'media': 'screen,projection',
},
},
}
PIPELINE_JS = {
'actions': {
'source_filenames': (
'js/nifty.js',
'feedback/js/feedback-form.js',
),
'output_filename': 'js/nifty.js',
}
}
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_DISABLE_WRAPPER = True
PIPELINE_ENABLED=True
答案 0 :(得分:1)
您确定public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
private void appendFile(JLabel jLab0x28, Socket client)
{
try
{
if(!continueMe)
{
//fileOut.close();
//fileOut = null;
fw.close();
fw = null;
in.close();
System.gc();
jLab0x28.setText("<html> <font color='red'> Socket is closed "+client.isClosed()+" </font> </html>");
System.out.println("File size after discontinuing "+
humanReadableByteCount(new File("C:\\ISSUE124_Resolved.txt").length(), true) );
}
if(!client.isClosed())
{
try
{
String data = in.readObject().toString();
System.out.println("File size is "+
humanReadableByteCount(new File("C:\\ISSUE124_Resolved.txt").length(), true) );
fw.write(data);
fw.flush();
//fileOut.write(data);
//fileOut.flush();
}
catch (EOFException exp)
{
continueMe = true;
exp.printStackTrace();
System.out.println("A Stream has finished "+exp.toString()+"\n");
}
catch (ClassNotFoundException exp)
{
exp.printStackTrace();
System.err.println(exp.toString());
continueMe = false;
}
}
}
catch(IOException exp)
{
try
{
//fileOut.close();
fw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
exp.printStackTrace();
System.err.println("Exception "+exp.toString());
jLab0x28.setText(exp.getMessage());
continueMe = false;
}
}
File size is 1.8 MB
File size is 1.8 MB
File size is 1.8 MB
Done
Closed Socket connection from client
File size after discontinuing 1.8 MB
是全局函数吗?确保您可以将其分配给search()
变量:
window
答案 1 :(得分:1)
我反过来做。
hasThing
然后拦截表单上的<form ... action="/nojs.html" ... id='searchform'>
事件。
submit
这样您就不需要在(function(){
var sf = document.getElementById('searchform');
sf.addEventListener('submit', function(ev){
ev.preventDefault();
// do here whatever "search()" needs to do
});
})();
命名空间中添加任何内容,它们与缩小的函数名称无关,并且具有禁用JS的浏览器会获得可读的错误页面。