Jump to content

document.write()


dreamwest

Recommended Posts

I wanted to include a static menu, but istead have it cached by an external js file. Is this a good idea, are there any security flaws in doing this??

 

js file

function show_menu(){
document.write("menu menu menu menu");
return;
}

 

and the menu.html

<script  type="text/javascript" src="menu.js"></script>
<body onload='show_menu();'>

Link to comment
Share on other sites

I see one problem

 

<script  type="text/javascript" src="menu.js"></script>
<body onload='show_menu();'>

 

Body onload are not triggered until the whole page is loaded.. and would be printed out on the bottom of the page. below the <body></html> and the site wouldn´t be to w3c standards.

 

I would use

<script  type="text/javascript" src="menu.js"></script>
<script type="text/javascript">show_menu();</script>

 

As for security no real validation security should be done in javascript since anyone with a bit of time and a few plugins could bypass it. But here this code is harmless unless you include your admin menu in the "menu.js" file aswell. The less the hacker knows, the harder it is for him to hack it.

Link to comment
Share on other sites

Using JavaScript to generate a menu is an awful idea. How will crawlers navigate your site?

 

 

What i really wanted to do was store part of the page such as the menu in memory. Im just not sure how to go about it without using a 3rd party app like eaccelerator -  theres gotta be some way to do it..

Link to comment
Share on other sites

Using JavaScript to generate a menu is an awful idea. How will crawlers navigate your site?

+1

 

What i really wanted to do was store part of the page such as the menu in memory. Im just not sure how to go about it without using a 3rd party app like eaccelerator -  theres gotta be some way to do it..

 

What exactly do you mean by "store part of the page such as the menu in memory"?

Link to comment
Share on other sites

The actual HTML to generate a menu is so minimal, there isn't even really any reason to cache it in the browser. It's a very, very small portion of the page. If you even have one tiny image on your page, it will take up significantly more data than any menu on any website ever (assuming your menu doesn't use images! But even if it does, you should just cache the images, not the HTML).

Link to comment
Share on other sites

The actual HTML to generate a menu is so minimal, there isn't even really any reason to cache it in the browser. It's a very, very small portion of the page. If you even have one tiny image on your page, it will take up significantly more data than any menu on any website ever (assuming your menu doesn't use images! But even if it does, you should just cache the images, not the HTML).

 

Im just obsessed with instant page loading, ive had some good success with preprocessors and compression. The page loading time has been reduced to (Time: 0.076079) front end, but thats with menus, if i can store the template in the servers memory im assuming that would so the trick.

 

Anyways i havent given up..

Link to comment
Share on other sites

As others have said, you're ruining your SEO if you do this. But if you absolutely must, then you should load the proper menu HTML the first time, and store it in a cookie. On subsequent page loads, if the cookie is present, load it from the cookie. This way it's on the users computer like you want, but the search engines will still get the benefit of getting the menu since it actually is loaded the first time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.