Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Including .JS file

Including .JS file

Scheduled Pinned Locked Moved ASP.NET
questionjavascriptannouncementhtmltutorial
5 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skoder
    wrote on last edited by
    #1

    Hello, i have added a .js file to my project / website. Normally i was just using the directly in the html to include js files. I have noticed that when using etc custom web controls, some often have .js files in them which is then automaticly included on the page as webresource.axd files, with a timestamp to make sure that if a new version of the axd (js file) is present it will be downloaded to the clients cache (example - WebResource.axd?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608). How do i use the same feature and make it include my .js file with a timestamp ? soo if i update the .js file it is automaticly updated. Side question. When using the build in validation on etc textboxes it automaticly includes a lot of javascript at the bottom of the page. Is there some way i can make it put it in a .js file soo it is cached everytime the page loads ? Is it not recommended to use the build in validation ? and instead write the validation myself and put it in a .js file ? Martin. :) ps., I know that if i need to add it at runtime i can use the RegisterClientScriptBlock and RegisterStartupScript in the Page_Load(). But that is not what i want to do in this case.

    M 1 Reply Last reply
    0
    • S Skoder

      Hello, i have added a .js file to my project / website. Normally i was just using the directly in the html to include js files. I have noticed that when using etc custom web controls, some often have .js files in them which is then automaticly included on the page as webresource.axd files, with a timestamp to make sure that if a new version of the axd (js file) is present it will be downloaded to the clients cache (example - WebResource.axd?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608). How do i use the same feature and make it include my .js file with a timestamp ? soo if i update the .js file it is automaticly updated. Side question. When using the build in validation on etc textboxes it automaticly includes a lot of javascript at the bottom of the page. Is there some way i can make it put it in a .js file soo it is cached everytime the page loads ? Is it not recommended to use the build in validation ? and instead write the validation myself and put it in a .js file ? Martin. :) ps., I know that if i need to add it at runtime i can use the RegisterClientScriptBlock and RegisterStartupScript in the Page_Load(). But that is not what i want to do in this case.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi Martin, The use of the WebResource.axd file is one of many new features in the ASP.NET 2.0. This file extention is configured in the Mapping by default, and the request for this file will be serviced by the http handler System.Web.Handlers.AssemblyResourceLoader. If you want to implement the same thing in your ASP.NET 1.x application , then you simply provide a custom http handler for that and you can specify the timestamp in the query string as you see in the ASP.NET 2.0. Basically, there are two common ways to make a custom http handler. + Make a custom http handler with the .ashx extension. The .ashx extension is configured in the Mapping by default, so you don't need to do that, and this file will be responsible for servicing the client script requests.

      <script language="javascript"
      src="MyResource.ashx?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608"
      type="text/javascript">
      </script>

      + Make a custom http handler and compile it to an assembly. This handler can be used to service the requests for a specific file extention, you can use whatever you want such as .myjs ... And you need to make sure two things: the file extention is added to the Mapping table, and configure this custom http handler in the web.config file to handle for the custom file extension.

      <script language="javascript"
      src="MyResource.myjs?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608"
      type="text/javascript">
      </script>

      If you don't want to use a custom http handler, you'll have to update the .js file so that it is automatically updated and it should not be cached at the client side. Skoder wrote: When using the build in validation on etc textboxes it automaticly includes a lot of javascript at the bottom of the page. Is there some way i can make it put it in a .js file soo it is cached everytime the page loads ? IMO, you don't need to worry about this since the ASP.NET 2.0 actually supports the cacheability for the web resources. Skoder wrote: Is it not recommended to use the build in validation ? and instead write the validation myself and put it in a .js file ? That all depends on your demand. If the built-in validation can meet your demand, then you simply use it instead of taking time to rewrite. If that cannot, you may think about implementing your own custom validator that not only works at the client side, but also at the server side. For more

      S 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Martin, The use of the WebResource.axd file is one of many new features in the ASP.NET 2.0. This file extention is configured in the Mapping by default, and the request for this file will be serviced by the http handler System.Web.Handlers.AssemblyResourceLoader. If you want to implement the same thing in your ASP.NET 1.x application , then you simply provide a custom http handler for that and you can specify the timestamp in the query string as you see in the ASP.NET 2.0. Basically, there are two common ways to make a custom http handler. + Make a custom http handler with the .ashx extension. The .ashx extension is configured in the Mapping by default, so you don't need to do that, and this file will be responsible for servicing the client script requests.

        <script language="javascript"
        src="MyResource.ashx?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608"
        type="text/javascript">
        </script>

        + Make a custom http handler and compile it to an assembly. This handler can be used to service the requests for a specific file extention, you can use whatever you want such as .myjs ... And you need to make sure two things: the file extention is added to the Mapping table, and configure this custom http handler in the web.config file to handle for the custom file extension.

        <script language="javascript"
        src="MyResource.myjs?d=5Tihy985xjPUFjtk9Szp5A2&t=632543073887980608"
        type="text/javascript">
        </script>

        If you don't want to use a custom http handler, you'll have to update the .js file so that it is automatically updated and it should not be cached at the client side. Skoder wrote: When using the build in validation on etc textboxes it automaticly includes a lot of javascript at the bottom of the page. Is there some way i can make it put it in a .js file soo it is cached everytime the page loads ? IMO, you don't need to worry about this since the ASP.NET 2.0 actually supports the cacheability for the web resources. Skoder wrote: Is it not recommended to use the build in validation ? and instead write the validation myself and put it in a .js file ? That all depends on your demand. If the built-in validation can meet your demand, then you simply use it instead of taking time to rewrite. If that cannot, you may think about implementing your own custom validator that not only works at the client side, but also at the server side. For more

        S Offline
        S Offline
        Skoder
        wrote on last edited by
        #3

        Hello, thanks a lot for your answer. I actually uses Asp.Net 2.0 (should have mentioned it) are there any build in functions for accomplishing the same ? The javascript code i am talking about getting into a .js file is not cached i guess, as it is written out in the bottom of the html page in between all the html tags. I hadnt thought about that it was not only client side the validation works, but also server side. If i could just rewrite the client side validation my self it would have been a good idea it seems. When using the login control and the build in validation the code is more than 32 kb ! ... and i think it could have been something like 2-5 kb... hmmm... No way to just rewrite the client side validation and keep the server side ? etc remove the client side validation check ? Thanks again for your answer.

        S 1 Reply Last reply
        0
        • S Skoder

          Hello, thanks a lot for your answer. I actually uses Asp.Net 2.0 (should have mentioned it) are there any build in functions for accomplishing the same ? The javascript code i am talking about getting into a .js file is not cached i guess, as it is written out in the bottom of the html page in between all the html tags. I hadnt thought about that it was not only client side the validation works, but also server side. If i could just rewrite the client side validation my self it would have been a good idea it seems. When using the login control and the build in validation the code is more than 32 kb ! ... and i think it could have been something like 2-5 kb... hmmm... No way to just rewrite the client side validation and keep the server side ? etc remove the client side validation check ? Thanks again for your answer.

          S Offline
          S Offline
          Skoder
          wrote on last edited by
          #4

          I can see that the validation control have a property called EnableClientScript... i guess it is possible to disable only the client side validation then ... :-) soo now i only have the question about the timestamp thing in asp.net 2.0 left :-)

          M 1 Reply Last reply
          0
          • S Skoder

            I can see that the validation control have a property called EnableClientScript... i guess it is possible to disable only the client side validation then ... :-) soo now i only have the question about the timestamp thing in asp.net 2.0 left :-)

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            I have no idea why I did not receive any notification email of the site about your reply, and just happen to know it. You are correct here. Basically, the built-in validators should work on the server side, and the client side is optional and you can disable that by setting the EnableClientScript property to false. Skoder wrote: soo now i only have the question about the timestamp thing in asp.net 2.0 left I forgot to tell you that you can also use the two ways provided in my previous post to implement a custom http handler in the ASP.NET 2.0. In the handler, you can provide a snippet of code to process the timestamp pamareter in the query string like the ASP.NET 2.0 does.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups